Deploying to Kubernetes from Jenkins
Fast recall
Quick revision
Core answer
End-to-end CD pipeline knowledge including container orchestration
Using a hardcoded image tag instead of the build number — losing traceability between build and deployment
Mention Helm for parameterized deployments and ArgoCD for GitOps-style continuous delivery
Interview-ready guide
Interview answer
Deploying to Kubernetes from Jenkins requires a kubeconfig credential injected into the pipeline and kubectl or Helm available in the agent environment. The pipeline should verify the deployment completes before reporting success.
Credential and tooling setup
- Store the kubeconfig file as a Jenkins
Filecredential —withCredentials([file(credentialsId: 'kubeconfig-prod', variable: 'KUBECONFIG')])injects the file path into theKUBECONFIGenvironment variable, whichkubectlreads automatically - Never commit kubeconfig files to the repository — they contain cluster server addresses and authentication tokens that grant cluster access to anyone who can read the file
- Use a namespaced Service Account with RBAC restricted to the deployment target namespace — the Jenkins CI service account needs
get,list,create,update,patchon Deployments and Services in the target namespace; not cluster-admin
Deploy steps and rollout verification
kubectl set image deployment/payment-service app=${IMAGE_NAME}:${IMAGE_TAG} -n productiontriggers a rolling update from the pipeline — simpler than applying a full YAML for routine image updateskubectl rollout status deployment/payment-service -n production --timeout=300swaits up to 5 minutes for the rollout to complete and exits with a non-zero code if it times out or a new Pod fails readiness — this is how the pipeline knows whether the deployment succeeded, not just whether thekubectlcommand ran- Without
rollout status, the pipeline reports success the moment the rolling update starts — a broken new image that fails readiness probes causes the pipeline to show green while production traffic is still on the old version
Helm-based deployments
helm upgrade --install payment-service ./helm/payment-service --set image.tag=${IMAGE_TAG} -n production --wait --timeout 5mcombines install and upgrade, waits for rollout, and fails the pipeline if pods do not become ready —--waitis the Helm equivalent ofkubectl rollout status- Use Helm's
--atomicflag for canary or risky deployments — on failure, Helm automatically rolls back to the previous release rather than leaving a partially updated state
Deploying to Kubernetes from Jenkins
Direct Answer
Jenkins deploys to Kubernetes using kubectl commands with the kubeconfig stored as a Jenkins File credential. The pipeline builds a Docker image tagged with the build number, pushes to a registry, then runs kubectl set image to trigger a rolling deployment.
Common Mistakes & Pitfalls
Using a hardcoded image tag instead of the build number — losing traceability between build and deployment
Check your understanding
Answer these without looking back at the article.
- How do you implement canary deployments in Jenkins with Kubernetes?
- How do you handle rollbacks in a Jenkins Kubernetes pipeline?
- What is the GitOps approach and how does it complement Jenkins?
Related interview prep categories
1Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.