How to Connect Jenkins to a Kubernetes Cluster Using the Kubernetes Plugin
This guide walks you through adding a Kubernetes cloud in Jenkins, extracting and decoding the required certificates from the kube config, creating a client P12 file with OpenSSL, uploading the credentials, and testing the connection to ensure seamless CI/CD integration.
To integrate Jenkins with a Kubernetes cluster, start in Jenkins System Management → System Settings and add a new cloud, selecting Kubernetes from the dropdown.
Enter a name for the cloud (any value) and provide the Kubernetes API server URL (e.g., https://192.168.0.6:6443 ).
On the target Jenkins node, retrieve the /root/.kube/config file: cat /root/.kube/config The file contains sections such as certificate-authority-data , client-certificate-data , and client-key-data .
Extract and decode the certificate-authority-data to a PEM file:
echo LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN5RENDQWJDZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRJd01EVXlPVEUwTlRnMU5Gb1hEVE13TURVeU56RTBOVGcxTkZvd0ZURVRNQkVHQTFVRQpBeE1LYTNWaVpYSnVaWFJsY3pDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnRVBBRENDQVFvQ2dnRUJBTWh6CmE5bkc5NFp1SVZNZEp0NGo1dGlYcEl2WmIvczFKMVNuTVhYREt0djVqQk4xU0NoMU1VU3dYWVNlLzdVWGtjUWwKTHlUTThQVmdtY0d5TFFiOGJxZDRvS3FRQW1ZR2UzNHRtN3FoYzExSEF5V2JvSWt4QmMyV21DNmwxc1U3MGlDNQpqY216ZGMrR3h2a0MyQmx2NE1Gam5YTmwxRkF2OTdhT0pIemh4UUJwanZhMUdrdkJoVWEvdDh6Mm5GVTlwVUVrClgzZGVoNWJmRi91WVVRRlJlUEVuZHdrdGxnd1V4VUN2ZDJNNFBsOWhQMDA0L3gvbGZOeEFBTGRpNkhMOCtoSFUKeWRSTjV5dEl2Wm5ib093MXEyUlJnWU9sVEVDUFRNYmFCZks0STBkVjFkYVZVK3l2OGo1QmVIWktabE1pbGxzNApuSWJFOXU4UlR0cjl5anNlbmRFQ0F3RUFBYU1qTUM... | base64 -d > /opt/crt/ca.crtSimilarly decode client-certificate-data and client-key-data to client.crt and client.key :
echo LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0t... | base64 -d > /opt/crt/client.crt
echo LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tL... | base64 -d > /opt/crt/client.keyCreate a PKCS#12 client certificate ( cert.pfx ) that Jenkins can use:
openssl pkcs12 -export -out /opt/crt/cert.pfx -inkey /opt/crt/client.key -in /opt/crt/client.crt -certfile /opt/crt/ca.crtYou will be prompted to set an export password; remember it for later.
In the Jenkins Kubernetes cloud configuration, upload the generated cert.pfx as the credential and enter the same password.
Test the connection by specifying the namespace (use the name field from the cluster section of the original config file).
After a successful test, Jenkins can schedule pods on the Kubernetes cluster, enabling fully automated CI/CD pipelines.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Full-Stack DevOps & Kubernetes
Focused on sharing DevOps, Kubernetes, Linux, Docker, Istio, microservices, Spring Cloud, Python, Go, databases, Nginx, Tomcat, cloud computing, and related technologies.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
