In this lesson, you’ll learn how to configure a Jenkins pipeline to deploy a Dockerized application to a Kubernetes cluster using AWS EKS. The guide covers setting up Jenkins credentials, creating the pipeline, reviewing the Jenkinsfile, and troubleshooting file permission issues with the kubeconfig file.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
1. Configuring Credentials in Jenkins
Begin by navigating to Manage Jenkins → Credentials. Note that Docker credentials are preconfigured. You now need to create a credential for the kubeconfig file, which typically resides in your home directory at.kube/config.

/home/username/.kube/config) and assign a credential ID such as kubeconfig-credentials-id.

2. Creating the Jenkins Pipeline
Next, set up a new pipeline project. Click on New Item, give it a name (for example, “Amazon EKS Pipeline”), and select Pipeline as the project type.



3. Reviewing and Updating the Jenkinsfile
The Jenkinsfile outlines the environment variables and defines various stages for building, testing, and deploying your application. It includes credentials for the kubeconfig file and AWS keys, which are necessary for working with Amazon EKS. Below is the enhanced Jenkinsfile that includes stages for environment setup (with troubleshooting for kubeconfig permissions), testing, Docker Hub login, image building and pushing, and deployments to both staging and production clusters.- Setup: Lists and updates kubeconfig file permissions to ensure Jenkins has write access. It then installs the required Python dependencies.
- Test: Runs the test suite using pytest.
- Login to Docker Hub: Authenticates with Docker Hub using stored credentials.
- Build and Push Docker Image: Builds the Docker image, verifies it by listing images, and then pushes it to Docker Hub.
- Deploy to Staging: Switches to the staging Kubernetes context, updates the deployment’s image, retrieves the service endpoint, and runs acceptance tests with K6.
- Deploy to Production: Switches the Kubernetes context to production and updates the deployment with the new image.
4. Troubleshooting File Permission Issues
During one of the builds, a file permission error occurred when attempting to change the Kubernetes context, indicating that the kubeconfig file was not writable. To resolve this issue, the Jenkinsfile was enhanced with diagnostic commands that:- List the kubeconfig file permissions using
ls -la $KUBECONFIG. - Adjust file permissions with
chmod 644 $KUBECONFIG. - Confirm the updated permissions before proceeding.
kubectl config use-context) will execute without error.

5. Updating Application Code
After successfully deploying the initial version, you may update your application code. For example, consider the following HTML snippet for a simple Todo App (version 1):By following these steps, you can implement a robust Jenkins pipeline that automates the build, testing, and deployment of a Dockerized application on Kubernetes using Amazon EKS. This streamlined pipeline also addresses common permission issues, ensuring a smooth continuous delivery workflow.
Automating the deployment with Jenkins reduces manual errors and accelerates your development pipeline, helping you achieve faster delivery cycles while maintaining consistency across environments.