Jenkins集成k8s报错:Error testing connection https://kubernetes.default.svc.cluster.local: Failure

背景:jenkins部署在k8s中的命名空间infra中api

 

 Jenkins集成k8s报错  链接测试报错:测试

Error testing connection https://kubernetes.default.svc.cluster.local: Failure executing: GET at: https://kubernetes.default.svc.cluster.local/api/v1/namespaces/defualt/pods. Message: Forbidden!Configured service account doesn't have access. Service account may have been revoked. pods is forbidden: User "system:serviceaccount:infra:default" cannot list resource "pods" in API group "" in the namespace "defualt".spa

意思:serviceaccount中 infra:default 没有权限“GET”这个命名空间的 "pods"。权限是“get”对象是“pods”。3d

出处:https://www.cnblogs.com/liucx/code

 

解决办法是:须要给infra:default赋权get去访问pods。对象

出处:blog

1.新建一个service-reader-cluster-role.yaml
vi service-reader-cluster-role.yaml部署

kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  namespace: infra
  name: service-reader
rules:
  - apiGroups: [""]
    resources: ["services"]
    verbs: ["get", "watch", "list"]
  - apiGroups: [""]
    resources: ["pods"]
    verbs: ["get","list","patch","watch"]

2.添加serviceacount的binding
kubectl create clusterrolebinding service-reader-pod --clusterrole=service-reader --serviceaccount=infra:defaultget

验证:kubectl -n infra get clusterrolebinding|grep service-reader-podkubernetes

 

而后就能够了。

相关文章
相关标签/搜索