亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在非默認命名空間中部署時,Cluster Config 無法獲取 Pod

在非默認命名空間中部署時,Cluster Config 無法獲取 Pod

Go
小怪獸愛吃肉 2023-05-08 18:04:02
當我將 golang 服務部署到命名空間以外的任何default命名空間時,該服務無法檢索任何命名空間上的 pod。default使用 golang client-go api,部署在命名空間上的相同服務可以完美運行。這是一個安全問題嗎?謝謝。
查看完整描述

3 回答

?
汪汪一只貓

TA貢獻1898條經驗 獲得超8個贊

這個問題是權限問題。由于您正在使用rest.InClusterConfig(config)創建客戶端。這意味著它使用 pod 的服務帳戶作為憑證。因此,請檢查該服務帳戶是否具有在任何命名空間中獲取 pod 的權限。


如果 pod 中的服務帳戶未定義,則它將使用default服務帳戶。


如果您的集群中啟用了 RBAC,則檢查該命名空間中的角色綁定,以確定您的服務帳戶是否具有權限。


# to see the list of role bindings in 'default' namespace

kubectl get rolebindings --namespace default

查看具體rolebinding


kubectl get rolebindings ROLE-BINDING-NAME --namespace default -o yaml

您還可以創建角色和角色綁定以授予權限。

查看完整回答
反對 回復 2023-05-08
?
翻閱古今

TA貢獻1780條經驗 獲得超5個贊

以下是我在 minikube 集群上使用的方法,使默認服務帳戶能夠訪問公共資源上的 crud 操作。明顯的警告是您需要在真實集群上小心。


apiVersion: rbac.authorization.k8s.io/v1

kind: Role

metadata:

  name: crud-role

  namespace: default

rules:

- apiGroups: ["", "apps", "batch"]

  resources: [ "deployments", "jobs", "pods", "replicasets", "services" ]

  verbs: [ "create", "get", "list", "delete"]

---

apiVersion: rbac.authorization.k8s.io/v1

kind: RoleBinding

metadata:

  name: crud-role-binding

  namespace: default

roleRef:

  apiGroup: rbac.authorization.k8s.io

  kind: Role

  name: crud-role

subjects:

  - kind: ServiceAccount

    name: default

    namespace: default


查看完整回答
反對 回復 2023-05-08
?
POPMUISE

TA貢獻1765條經驗 獲得超5個贊

我收到了類似的錯誤,但是來自在默認命名空間中使用 golang 客戶端的 pod:


pods 被禁止:用戶“system:serviceaccount:default:default”無法在集群范圍內列出 API 組“”中的資源“pods”


戈蘭代碼片段:


if configMode == "IN_CLUSTER" {

? ? // creates the in-cluster config

? ? config, err := rest.InClusterConfig()

? ? if err != nil {

? ? ? ? panic(err.Error())

? ? }

? ? return config, err

}它僅針對獲取和列表進行了修改:


apiVersion: rbac.authorization.k8s.io/v1

kind: ClusterRole

metadata:

? name: query-role

? namespace: default

rules:

- apiGroups: ["", "apps", "batch"]

? resources: [ "deployments", "jobs", "pods", "replicasets", "services" ]

? verbs: [ "get", "list" ]

---

apiVersion: rbac.authorization.k8s.io/v1

kind: ClusterRoleBinding

metadata:

? name: query-role-binding

? namespace: default

roleRef:

? apiGroup: rbac.authorization.k8s.io

? kind: ClusterRole

? name: query-role

subjects:

? - kind: ServiceAccount

? ? name: default

? ? namespace: default


查看完整回答
反對 回復 2023-05-08
  • 3 回答
  • 0 關注
  • 171 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號