io.kubernetes.client.openapi.ApiException: Forbidden 解决

使用spring-cloud-kubernetes时候,程序启动报错:

 .KubernetesClientConfigMapPropertySource : Unable to get ConfigMap xxx in namespace xxxx
io.kubernetes.client.openapi.ApiException: Forbidden 

其实是我们namespace默认的serviceaccount没有访问configmaps权限。

spring-cloud-kubernetes需要的权限包括:

 ["configmaps", "pods", "services", "endpoints", "secrets"]

并且仅仅需要读的权限。

 

 

 解决办法:

知道了错误原因,就知道咋解决了,就是给默认的serviceaccout设置上以上资源对象的读权限即可。

例如:

kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  namespace: 你自己的namespace
  name: default-read-role
rules:
  - apiGroups: ["", "extensions", "apps"]
    resources: ["configmaps", "pods", "services", "endpoints", "secrets"]
    verbs: ["get", "list", "watch"]

---

kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: default-role-read-binding
  namespace: 你自己的namespace
subjects:
- kind: ServiceAccount
  name: default
  apiGroup: ""
roleRef:
  kind: Role
  name: default-read-role
  apiGroup: ""

以上只需要改namespace就能解决报错问题。

 

================================================

注意的是:Role指定的是默认的sa访问自己namespace的权限,如果要访问集群资源或者其它namespace的资源,请使用clusterrole和clusterrolebinding

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值