【发布时间】:2020-09-17 05:43:13
【问题描述】:
似乎我的 AKS 集群无法对 k8s api 执行基本请求,即对 pod 使用集群内令牌。当我使用本地机器上的相同代码时,一切正常,即使用 config.load_kube_config 。
我正在使用python k8s客户端11.0.0,我正在通过config.load_incluster_config()加载配置。我收到以下错误:
HTTP response body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"Unauthorized","reason":"Unauthorized","code":401}
在尝试简单地列出我的 pod 时(使用 client.list_namespaced_pod)。我还尝试执行原始获取请求,但结果相同。
我尝试扩展集群角色以专门访问资源,这里是我的集群角色和集群角色绑定:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: clusterrolename
rules:
- apiGroups:
- ""
resources:
- pods
- namespaces
verbs:
- get
- list
- apiGroups:
- metrics.k8s.io
resources:
- '*'
verbs:
- get
- list
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: clusterrolebindingname
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: clusterrolename
subjects:
- kind: ServiceAccount
name: default
namespace: mynamespace
但我总是得到相同的结果。
同样的方法在 linux 和 windows 节点上效果不同。
之前在linux机器(纯linux集群)上使用同样的方法是成功的。
会不会和SDK版本有关? 集群中可能有不同的东西吗? 有谁知道我如何检索任何特定 ServiceAccount 的授权列表?
【问题讨论】:
标签: python kubernetes azure-aks