[英]K8S Read config map via go API
我有一個配置映射,我需要通過 api 從 K8S 讀取
我創建了一個集群角色
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: zrole
rules:
- apiGroups: [""]
resources: ["configmaps"]
verbs: ["get", "list"]
和集群角色綁定
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: z-role-binding
subjects:
- kind: Group
name: system:serviceaccounts
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: zrole
配置圖
apiVersion: v1
kind: ConfigMap
metadata:
name: z-config
namespace: fdrs
data:
avr: client1
fuss: xurbz
代碼是這樣使用的
clientSet.CoreV1().ConfigMaps(uNamespae)
當我在本地運行代碼(並向 GO api 提供 kubeconfig)時,我能夠獲取配置映射數據,但是當我在集群內運行代碼時,我收到錯誤: invalid token
,知道我在這里遺漏了什么?
檢查 pod 規范中的automountServiceAccountToken
。 默認情況下它設置為true
,但也許您已禁用它。
使用官方GO客戶端。 默認情況下,它會讀取正確的配置和令牌。 https://github.com/kubernetes/client-go/blob/master/examples/in-cluster-client-configuration/main.go
如果不使用,則使用正確的配置: https : //kubernetes.io/docs/tasks/administer-cluster/access-cluster-api/#directly-accessing-the-rest-api-1
檢查 pod 中的令牌: /var/run/secrets/kubernetes.io/serviceaccount/token
並使用kubernetes
服務。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.