Learn how to create a Docker image using the Jenkins Pipeline, which will start an AWS EKS deployment. At Bobcares, with our AWS Support Services, we can handle your AWS issues.
AWS EKS-Jenkins Pipeline
Jenkins is a build server that automatically makes the code repository. Jenkins does this with a Jenkinsfile, a configuration file. It includes the procedure for building, pushing, and deploying user applications. While EKS is a managed cloud service that offers Kubernetes clusters that can manage workload applications.
Here, we will see the steps to make a Docker image using a Jenkinsfile workflow. Then we will also see how to upload that image to the AWS ECR.
Pre-requisites
- AWS Account
- GitHub Account
- Jenkins instance set up with a Pipeline
Set up AWS
We have to make an access key and an ECR repository to store the image. So that we can set up AWS for Jenkins. To create an access key, navigate to Amazon Console >> IAM >> Users [your user] >> Security credentials >> Create Access Key. Now the browser will download a file. The file contains the Access Key ID and the Secret Access Key. We need this to authenticate Jenkins to AWS.
In order to create a repository, go to Amazon Console >> ECR >> Create Repository. Every image we publish needs to have its own repository. So we must set up it. It should be given the same name as the image. It will be listed under Repositories in Amazon ECR. In the URI field, make a note of the zone it belongs to.
Set up AWS Cluster
Here, we are using the command-line option to set up the AWS cluster.
- Firstly, log in to the AWS command line using
aws login
. - Now execute
aws configure
. - Now provide Access Key ID and Secret Access Key.
- Now we can create the AWS cluster.
eksctl create cluster \
--name my-cluster \
--region us-east-2 \
--fargate
After the Cluster setup, we must make a file called deployment.yml in the repository’s root directory.
apiVersion: apps/v1 kind: Deployment metadata: name: underwater-app-jenkins labels: app: octopus-underwater-app spec: selector: matchLabels: app: octopus-underwater-app replicas: 3 strategy: type: RollingUpdate template: metadata: labels: app: octopus-underwater-app spec: containers: - name: octopus-underwater-app image: 720766170633.dkr.ecr.us-east-2.amazonaws.com/octopus-underwater-app:latest ports: - containerPort: 80 protocol: TCP imagePullPolicy: Always
Then make a file called Jenkinsfile in the repository’s root directory.
pipeline { agent any options { skipStagesAfterUnstable() } stages { stage('Clone repository') { steps { script{ checkout scm } } }
stage('Build') { steps { script{ app = docker.build("octopus-underwater-app") } } } stage('Test'){ steps { echo 'Empty' } } stage('Push') { steps { script{ docker.withRegistry('https://720766170633.dkr.ecr.us-east-2.amazonaws.com', 'ecr:us-east-2:aws-credentials') { app.push("${env.BUILD_NUMBER}") app.push("latest") } } } } stage('Deploy'){ steps { sh 'kubectl apply -f deployment.yml' } } } }
Jenkins will copy the image, compile it, test it, push it, and deploy it to an EKS cluster. The deployment file we earlier prepared is used by Jenkins to complete this.
[Searching for a solution to another query? We are just a click away.]
Conclusion
In this article, we use Jenkins to deploy a web application to EKS. This showed how Jenkins may be configured to set up the procedures required to deploy the code repository.
PREVENT YOUR SERVER FROM CRASHING!
Never again lose customers to poor server speed! Let us help you.
Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.
var google_conversion_label = "owonCMyG5nEQ0aD71QM";
That was a very nice article, but leave one question my mind. You created a new cluster and deployed to it, what if I have to a deploy a new images to a cluster that is already running an app.
Also I doe not see the name of the cluster “my-cluster” in jenkines and deployment file, how does it know the deployment goes to which cluster?
Hi,
Please contact our support through live chat(click on the icon at right-bottom).