Jenkins Views 4

Connecting Jenkins to Kubernetes

Connecting Jenkins to Kubernetes image 1

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-token
  • token mount

    kubectl apply -n jenkins -f jenkinstoken.yaml
  • Confirm that the token is mounted

    kubectl describe serviceaccounts -n jenkins jenkins
  • Grant permissions to the serviceaccount

    kubectl create rolebinding jenkins-admin-binding --clusterrole=admin --serviceaccount=jenkins:jenkins -n jenkins
  • Copy 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.
Connecting Jenkins to Kubernetes image 2

For Kubernetes URL, enter the address of your Kubernetes API endpoint. Fill in the namespace and the rest, then run the test.

Reactions

Comments 0

A nickname and a password are required. The same password edits or deletes the comment later. Comments appear after a review.

Comments appear after a review. The password is used again to edit or delete.