GIT LAB CI/CD For Kubernetes On AWS

Note:- Already my cluster is running on AWS on Kops and Eks we are using both with this and setting up a new pipeline using gitlab for one of micro service.

Introduction on Git lab

This is a short intro on Git lab Its free and open source .It do almost everything that GitHub (VCS) does, so it is like GitHub, but here we have free private repositories that GitHub doesn’t .In this, you can attach any file to any issue. You can’t do this inside GitHub.Now days also used for CI/CD purpose .It is free for public repositories and for private one it is paid.It require less human intervention or even no intervention at all, from the development of new code until its deployment.

Git-Lab that build ,test and deploy. the software whenever developer pushes code to application. Git-Lab CD (Continuous Deployment) is a software service that places the changes of every code in the staging/production environment which results in every day deployment of staging/production environment .

Now a day mostly the people use Jenkins for CI/CD But as i found that the Git lab CI/CD is also a very simple and easy to deploy tool

The following points describe usage of Git-Lab CI/CD -

  • It’s very fast easy to use for deployment and development.
  • Allows teams to develop faster, with more confidence.
  • Passing variable very easily and faster.
  • Succeed, the pipeline moves on to the next stage.
  • Fail, the next stage is not (usually) executed and the pipeline ends early.

Some point are very important to keep in mind

  • One should be very familiar with Yaml or JSON i usually use the Yaml file.
  • To check you Yaml is correct you can you Ci-lint

Starting with Git lab CI/CD

Scenario

Let’s say we have a Node.js application/web . We need to create a pipeline. Here we are pushing our code into four phases: setup,test,build and deploy.

Regular pipeline graphs

prerequisites:-

  • Gitlab Runner setup
  • Dockerfile
  • .gitlab-ci.yml
  • deployment.yaml
  • service.yaml
  • variables setup in Git-lab
  • secrets.yaml (optional)
  • Gitlab registry / Docker hub registry:- Enabled

Note:- Before running this pipeline user must be added in gitlab setting>members>”<name of the user>” .When you have added new options to the ConfigMap, you need to delete each GitLab CI Runner Pod. This is currently a limitation of using Kubernetes envFrom instead of env directly (envFrom helps keep manifests shorter by moving the environment variables out to ConfigMaps or Secrets).

  • Gitlab Runner setup

In GitLab CI, Runners run the code defined in .gitlab-ci.yml. They are isolated (virtual) machines that pick up jobs through the coordinator API of GitLab CI. -— Docs

Namespace

Replace <name of the namespace> with a name for the namespace in which the GitLab CI builds are run. The separate namespace for the GitLab CI builds is useful for detecting stuck containers (for example when there was an issue with the runner not cleaning up).

ConfigMap for the Environment Variables and Script

GO to setting > CI/CD > Runner (click on expand button)

  • Dockerfile

This is a Dockerfile for Node.js project this may varies according you your project you can write according to you projects use cases .

Environment variables in Git lab

For passing of Run time variables we can you Environment variables in Gitlab go to Setting click on CI/CD now we can see Environment variables click on expand button enter you variables click on save variables. Also you can define to the according environment and you can also protect them by protected on button.

  • .gitlab-ci.yml

For start with the git lab CI/CD we have to create a .gitlab-ci.yml file This is a sample example file you can see below.

Point while writing this file

Stages

In above deployment staging step at last line I’m using . deploy/scripts/deploy_app.sh

In this file we are confirming the variables that i have passed are the same or not and also we set up the docker image which will run on the pod which will get launched .

  • Deployment.yaml

In Kubernetes whenever you want to deploy any new pod we need a deployment,yaml file for more references how to write a yaml file you can take a reference of the Kubernetes document

Currently i can help you with my file remember to change you url of the registry .

  • service.yaml

In Kubernetes there are three ways to expose your service clusterip,nodeport and loadbalancer.

So, in this example i’m using a load balancer that will get created on AWS when you will describe the service you will get a host name and the on AWS one load balancer will also get created and you and hit on that URL and you can easily view your websites easily.

  • secrets.yaml

A Secret is an object that contains a small amount of sensitive data such as a password, a token, or a key. Such information might otherwise be put in a Pod specification or in an image; putting it in a Secret object allows for more control over how it is used, and reduces the risk of accidental exposure. — Docs

Command to check that deployment done correctly or not

For checking the deployment

kubectl get deployments -n <name of your namespace>

Command to check your pod

kubectl get pods -n <name of your namespace>

Command to check your service

kubectl get services -n <name of your namespace>

Command to check your secrets

kubectl get secrets -n <name of your namespace>

--

--

--

DevOps engineer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The backpack problem in Ising model

Best Open Source Programs for Student Developers

Understanding Ionic 2 navigation

What a VoiceOver Accessibility SNAFU Taught Us

Man with his head in his hand, staring at a laptop

Simplifying Salesforce platform development with SFDX

Continuously deploy Meteor apps to Azure

Reflections and advice; Passing Strategio’s Training Simulator

How I Stopped Being a Hater and Learned to Love Rails

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
Saket Jain

Saket Jain

DevOps engineer

More from Medium

Using Portainer with AWS Elastic Container Registry

How to publish private and public docker images to AWS ECR

Distributed “MinIO” Object storage setup on AWS infra

Creating a Kubernetes Cluster on AWS