
Connecting Jenkins to Kubernetes
Let’s connect Jenkins to Kubernetes.
Kubernetes prerequisites
- Create a namespace
kubectl create namespace jenkins - Create a serviceaccount
kubectl create serviceaccount jenkins --namespace=jenkins
From Kubernetes v1.20 onward, service account tokens are no longer created automatically because of a security change.
So you have to create a token yourself and mount it on the serviceaccount.
jenkinstoken.yaml
apiVersion: v1 kind: Secret metadata: name: jenkins annotations: kubernetes.io/service-account.name: jenkins type: kubernetes.io/service-account-tokentoken mount
kubectl apply -n jenkins -f jenkinstoken.yamlConfirm that the token is mounted
kubectl describe serviceaccounts -n jenkins jenkinsGrant permissions to the serviceaccount
kubectl create rolebinding jenkins-admin-binding --clusterrole=admin --serviceaccount=jenkins:jenkins -n jenkinsCopy the hash value
kubectl describe secret $(kubectl describe serviceaccount jenkins --namespace=jenkins | grep Token | awk '{print $2}') --namespace=jenkins
Connecting Jenkins
Dashboard -> Manage Jenkins -> manage credential -> add -> set it to secret text, then paste the hash value you copied above.
Dashboard -> Manage Jenkins -> Manage nodes -> Configure Clouds -> add kubernetes cloud
- You must install the Kubernetes plugin beforehand.

For Kubernetes URL, enter the address of your Kubernetes API endpoint. Fill in the namespace and the rest, then run the test.
Comments 0
A nickname and a password are required. The same password edits or deletes the comment later. Comments appear after a review.