Capstone Project Cloud DevOps Udacity

Jenkins pipeline for the rolling update using AWS EKS

I have noticed that many people are getting confused about the Capstone project. Here I am giving you a rough idea about the project.

Don’t be confused about this project. It’s really an easy project if you understand it properly. I am writing a few steps. If you follow those steps, you will be able to understand and finish it properly.

Necessary scripts and files:

  • CloudFormation Script. You can use your own CloudFormation scripts or else you can do it using AWS Management Console.
  • Jenkinsfile, Dockerfile.
  • Your app to deploy
  • Deployment and Service script for Kubernetes.

You can add your own files and scripts. Those are the necessary files you have to include for this project.

Steps

Install necessary packages and setup Jenkins

Run an EC2 instance. For free tire account use t2.micro. You can use any instance type, you want to run. Connect your EC2 instance using SSH. After that install Jenkins in the EC2 instance. To install run:

For information check this link: https://www.jenkins.io/doc/book/installing/#debianubuntu

Start the Jenkins server using sudo systemctl start jenkins command. Install the necessary plugins in Jenkins for implementing the pipeline. Such as Blue Ocean, AWS plugins, docker plugins, etc.

Install Docker in EC2 instance.

Run: sudo apt install docker.io

For more information check this link: https://phoenixnap.com/kb/how-to-install-docker-on-ubuntu-18-04

Start the docker service.

Run: sudo systemctl start docker

Note: You need to add a user to the docker group. Otherwise, you will get an error. To add a user run sudo usermod -a -G docker <username>

  • Add credentials for AWS and docker in Jenkins.
  • Create AWS EKS Cluster and Node group
  • Now you need to create an AWS EKS Cluster and node group. You can use your own CloudFormation script. Otherwise, you can use AWS CLI to create AWS EKS Cluster and node group. To create an AWS EKS Cluster and node group, you need to install aws-cli, eksctl, and kubectl in your EC2 instance, you have created earlier. Follow this link to install: https://docs.aws.amazon.com/eks/latest/userguide/getting-started-eksctl.html. After installing, run this command:

This command will automatically create two CloudFormation scripts for the EKS cluster and node group. It will create 3 EC2 instances as nodes. You can check in EC2 Dashboard in AWS Management Console. Like this:

Creating service and deployment

A Kubernetes Service is an abstraction that defines a logical set of Pods running somewhere in your cluster, that all provide the same functionality. When created, each Service is assigned a unique IP address (also called clusterIP). This address is tied to the lifespan of the Service, and will not change while the Service is alive. Pods can be configured to talk to the Service, and know that communication to the Service will be automatically load-balanced out to some pod that is a member of the Service

You can use a Load Balancer as a service. For more information follow this link: https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/

  • Create a kubectl configuration file to store the info of your cluster to interact later. Run:

kubectl config use-context command is used to switch between clusters. After your clusters, users, and contexts are defined in one or more configuration files, you can quickly switch between clusters.

For more information follow this link: https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/

Create the rolling deployment pipeline

  • Create a stage to lint
  • Create a stage to build a docker image
  • Create a stage to push the docker image
  • Create a stage to deploy.
  • Your pipeline will look like this:
  • You need to include kubectl apply -f deployment.ymlcommand in the deploy stage. It creates and updates resources in a cluster by running this command.

Run the pipeline. Run kubectl get deployments to check if the Deployment was created. Run kubectl get services/<image name>. You will get an Endpoint ID. You will get the External IP also. Use that link and copy in the browser search bar with the appropriate port you have exposed to see that your app is working correctly.

Now you need to check whether your rolling update is working or not. Update your image (change something in your app and you can use the version for this) and again deploy it to the cluster. This time use this command.

kubectl set image deployments/<appname> <appname>=<image>:<tag>

Then run kubectl rollout status deployments/<image>. You will get a message like a deployment “name” successfully rolled out. If you get that message then your rolling update is working correctly.

Thank you! I hope this blog will help you to do the Capstone project.

For more information visit https://github.com/sabbir420/capstone-project-cloud-devops.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store