Skip to content

Lab: Deploying EKS Microservices using Jenkins

mehulsharma2010 edited this page Aug 27, 2021 · 17 revisions

Deploying EKS Microservices using Jenkins

In this lab we will be doing below steps:

  • We will build the docker image and push it to ECR.
  • Then Pull the image on Spinnaker and try to do deployments with the help of Spinnaker.

Prerequisites

Before starting working on the Lab, Make sure you are sharing your GITHUB Token and YOUR_TEAM_NAME with Instructor of the workshop so that they can add your account in Spinnaker from the back-end.

Now Fork the Spinnaker-Study Repository into your Public Github account and then clone it to your local.

Notice the manifests/deploy-microservice.yml file, and see the Deployment, and the Service.

Now we need to make updates on the all the files present under manifests directory and replace mild-temper with YOUR-NAME or YOUR-TEAM-NAME .

After making the updates you are good to push your code back to your repository.

Lab Solution

Setting up a Jenkins job

  1. Open Jenkins and login with the username: spinnaker and password: timeisluxury

  2. Click on New Item, and a Pipeline Job in Jenkins

  3. Name your job <YOUR-TEAM-NAME>-microservice, and click Ok

  4. Under Build Triggers, select Poll SCM, and in the text area enter * * * * *.

  5. Under Pipeline, change Definition to Pipeline Script from SCM.

  6. Change SCM to Git, and enter your repository URL that you cloned for your team i.e. Spinnaker-Study repository

  7. Save and Build the Job and see if your docker image is getting push to ECR or not.

Setting up a Spinnaker Application

  1. Open Spinnaker, this is not secure so don’t place any personal information.

  2. Once there create an Application with the name: <YOUR-TEAM-NAME>-microservice

  3. Add your email as Owner Email

  4. In Repo Type, Choose github.

  5. In Repo Project, Enter Forked Repo Link.

  6. In Repo Name, Enter Name of your repositoey.

  7. In Cloud Providers, Choose KUBERNETES.

  8. Create an instance port of 80

  9. Click on Create to create the Application

Now you should inside the Application that you have created.

Creating a Pipeline

  1. Click on Pipelines, and click on "Configure a new pipeline"

  2. Under Pipeline Name, name it "ToStaging"

Github Expected Artifact

We will require two artifacts:

- The Deployment yaml from Github

- The Docker Container from ECR

Setting up the Github Expected Artifact

  1. In Configuration under the Expect Artifacts section, click on Add Artifact

  2. In Account field, choose your github account

  3. In File Path, enter manifests/deploy-microservice.yml, remember where you saw this entry

  4. In Display Name, enter 'deploy-microservice.yml'

  5. Check Use Default Artifact

  6. Select your determined github account

  7. Enter in your content url and keep in mind this is a different kind of url: https://api.github.com/repos/$ORG/$REPO/contents/$FILEPATH

 **For Example: https://api.github.com/repos/mehulsharma2010/spinnaker-study/contents/manifests/deploy-microservice.yml**
  1. In Commit/Branch enter master

Docker Registry Artifact

  1. In Configuration under the Add Artifacts section, Again click on Add Artifact

  2. In Account, choose Docker Registry Account

  3. In Docker Image, add 702037529261.dkr.ecr.us-west-2.amazonaws.com/ followed by <YOUR-TEAM-NAME>-microservice name. This will typically be your project name followed by microservice, ask the instructor to show what is on the ECR, or have them show you.

  4. In Display Name, enter '<YOUR-TEAM-NAME>-microservice'.

Adding a Docker Registry Container Trigger

  1. In Automated Triggers section, click Add Trigger

  2. In the Type drop-down field, select Docker Registry

  3. In the Registry Name field, select my-ecr-registry

  4. In the Image field, select your image.

Adding a Notification

  1. In the Notifications Section, click Add Notification Preference, this will produce a dialog box

  2. In the Notify Via, select Email

  3. In the Email Address, enter your email address

  4. Select all the boxes for all notification

Now we can SAVE the changes.

Adding a Deploy Stage

  1. In your pipeline, click on the Add Stage button

  2. In the Type field, select Deploy (Manifest)

  3. This will present some new sections and fields

  4. Go to the Deploy (Manifest) Configuration and Basic Settings section, in Account select eks-stage

  5. In the Manifest Configuration section, and for the Manifest Source, select Artifact

  6. In the Manifest Artifact select your deploy-microservice.yaml file

  7. In the Required Artifacts to Bind select your container artifact binding

Deploying to Staging

  1. Click on the pipelines icon.

  2. Click on Start Manual Execution

  3. Check Results

  4. If it doesn’t work, check configurations

If Pipline completes successfully then you can go to the Infrastructure section and explore what is happening there.

Deploying to Production

Creating a Pipeline

  1. Click on Pipelines, and click on "Configure a new pipeline"

  2. Under Pipeline Name, name it "ToProd"

Production Artifacts

  1. Declare the two artifacts that you expect from the previous pipeline

    a. One would be the Github reference to your kubernetes yml file

    b. The other would be a reference to your Docker artifact

Production Trigger

  1. In the new Pipeline Configuration, go to Automatic Triggers

  2. In the Type field select Pipeline

  3. In the Application field select your Application name (e.g. mehul-microservice)

  4. In the Pipeline field select toStaging, which was the pipeline that was created

  5. In the Pipeline Status select Successful

  6. For Artifact Constraints add deploy-microservice.yml and <YOUR-TEAM-NAME>-microservice

Adding a Deploy to Prod Stage

  1. In your pipeline, click on the Add Stage button

  2. In the Type field, select Deploy (Manifest)

  3. This will present some new sections and fields

  4. Go to the Deploy (Manifest) Configuration and Basic Settings section, in Account select eks-prod

  5. In the Manifest Configuration section, and for the Manifest Source, select Artifact

  6. In the Manifest Artifact select your deploy-microservice.yml file

  7. In the Required Artifacts to Bind select your container artifact binding

Put it all in motion

  • Make a change in your repository

  • Commit and Push

  • Ensure that your pipeline works!

Thank You