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
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
- Gitlab Runner setup
- 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
- Gitlab Runner setup
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)
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.
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
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 .
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 .
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.
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>