k8s部署的jenkins对接k8s集群
k8s部署的jenkins对接k8s集群
·
- 安装必要的插件
2. jenkins添加k8s集群
3. 添加相应的k8s集群信息
3.1点击测试连接时可能会报错
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:default:default" cannot list resource "pods" in API group "" in the namespace "defualt".
意思:serviceaccount中 default:default 没有权限“GET”这个命名空间的 "pods"。权限是“get”对象是“pods”。
解决办法是:需要给default:default赋权get去访问pods。
3.2编辑brac文件
vim 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"]
kubectl apply -f service-reader-cluster-role.yaml
3.3添加serviceacount的binding
kubectl create clusterrolebinding service-reader-pod --clusterrole=service-reader --serviceaccount=default:default
验证是否添加成功
kubectl get clusterrolebinding|grep service-reader-pod
service-reader-pod ClusterRole/service-reader 21m
以上这一步则表示测试成功
文章仅作为纪念保留,方便日后复习查看
更多推荐
已为社区贡献1条内容
所有评论(0)