因此,我正在使用Helm在K8S集群中部署Jenkins实例。
这是我关注的流程:
1)创建名为jenkins-pipeline
的命名空间。
kubectl get ns jenkins-pipeline -o yaml
apiVersion: v1
kind: Namespace
metadata:
creationTimestamp: 2018-09-15T16:58:33Z
name: jenkins-pipeline
resourceVersion: "25596"
selfLink: /api/v1/namespaces/jenkins-pipeline
uid: 9449b9e7-b908-11e8-a915-080027bfdbf9
spec:
finalizers:
- kubernetes
status:
phase: Active
2)创建名为jenkins-admin
INSIDE名称空间jenkins-pipeline
的ServiceAccount。
kubectl get serviceaccounts -n jenkins-pipeline jenkins-admin -o yaml
apiVersion: v1
kind: ServiceAccount
metadata:
creationTimestamp: 2018-09-15T17:02:25Z
name: jenkins-admin
namespace: jenkins-pipeline
resourceVersion: "25886"
selfLink: /api/v1/namespaces/jenkins-pipeline/serviceaccounts/jenkins-admin
uid: 1e921d43-b909-11e8-a915-080027bfdbf9
secrets:
- name: jenkins-admin-token-bhvdd
3)创建将我的ServiceAccount jenkins-admin
链接到ClusterRole cluster-admin
的ClusterRoleBinding。 (我知道这不是向我的部署分配这么多特权的最佳实践,而是我现在只是在本地进行测试)。
kubectl get clusterrolebindings.rbac.authorization.k8s.io jenkins-cluster-role-binding -o yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
creationTimestamp: 2018-09-15T16:58:33Z
name: jenkins-cluster-role-binding
resourceVersion: "25597"
selfLink: /apis/rbac.authorization.k8s.io/v1/clusterrolebindings/jenkins-cluster-role-binding
uid: 944a4c18-b908-11e8-a915-080027bfdbf9
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: jenkins-admin
namespace: jenkins-pipeline
4)将我的pod部署到命名空间jenkins-pipeline
中。
5)使用命名空间jenkins-pipeline
中的服务公开部署。
Jenkins非常正常,但是当我尝试测试Kuberenetes连接时,它却无法说明:
Error testing connection https://192.168.99.100:8443: Failure executing: GET at: https://192.168.99.100:8443/api/v1/namespaces/jenkins-pipeline/pods. Message: Forbidden!Configured service account doesn't have access. Service account may have been revoked. pods is forbidden: User "system:serviceaccount:jenkins-pipeline:default" cannot list pods in the namespace "jenkins-pipeline".
UI的片段如下:
据我所知,我已经对此进行了配置。我在名称空间中创建了serviceaccount,并赋予了该serviceaccount SUPER特权。但是,它无法在其自己的名称空间中列出Pod。任何帮助将不胜感激。
我试图在Jenkins UI中更改名称空间,但是我有一种感觉,即使我未声明它也默认为jenkins-pipeline
。
答案 0 :(得分:1)
多亏了David Maze的指示,我才知道了。我错过了一个至关重要的部分,那就是使我的部署使用新创建的ServiceAccount。
需要将其添加到spec.template.spec下的部署文件中:
spec:
containers:
- env:
- name: JAVA_OPTS
value: -Djenkins.install.runSetupWizard=false
image: jeunii/my-jenkins-base:1.0
imagePullPolicy: IfNotPresent
.
.
serviceAccount: jenkins-admin
.
.