Tuesday, August 16, 2022

Gitlab CI/CD with Kubernetes

 Gitlab CI/CD with Kubernetes

git lab is like github, we can store our code in gitlab, but its have more function apart from that:-
1. we can do CI/CD, we can do automation and we can create pipeline.
2. we have option to integrate with multiple services (like kubernetes, monitoring etc)
3. we have repository storage, for container image etc.


Gitlab agent
The GitLab Agent for Kubernetes ( agentk ) is an active in-cluster component for solving GitLab and Kubernetes integration tasks in a secure and cloud-native way. The agentk communicates to the GitLab Agent Server (KAS) to perform GitOps operations.

GitLab runner
GitLab Runner is an application that works with GitLab CI/CD to run jobs in a pipeline. You can choose to install the GitLab Runner application on infrastructure that you own or manage.

how to work in gitlab for CI/CD?
1. way to create one project and we use agent for connect to the cluster, and use runner for run CI/CD jobs in the pipeline.
2. create 2 project, 1st project connect with cluster, and use it for run yaml, manifest file, that you will building image in 2nd project.......and in second project you build code, using runner, you will run CI/CD pipeline.

3. Only CD job, you build on local and you upload image in gitlab repository, and with the help of gitlab agent, you will deploy on kubernetes cluster.

4. Only create 1 project, and using gitlab runner, you run kubernetes cluster cmd also to deploy on kubernetes cluster.

1. way
below project for ci/cd jobs we using .gitlab-ci.yaml file for config:
https://gitlab.com/manjeetyadav19/docker_test
and for agent go to Infrastructure - Kubernetes cluster - connect a cluster - in drop down - select the name of agent that you have mentioned in .gitlab/agent/nagyu-local.......and the configuration for the agent you have config file - .gitlab/agent/nagyu-local/config.yaml

2. way
create 2 project
1st for agent - https://gitlab.com/manjeetyadav19/docker-agent
2nd for ci/cd of app with the help of runner - https://gitlab.com/manjeetyadav19/docker-app

3. way
create 1 project only for CD,  with the help of gitlab agent deploy on kubernetes cluster:-
https://gitlab.com/manjeetyadav19/docker-agent

4. way
create 1 project only 1st do CD work with the help of runner, and then do some configuration on your kubernetes cluster server and then mention kubernetes deployment cmd in .gitlab-ci.yaml  to do deployment on kubernetes cluster.
https://gitlab.com/manjeetyadav19/docker-solo


how to install gitlab runner on your machine/cluster?
install binary or package
for register below is the cmd:
#sudo gitlab-runner register

if runner unable to connect not in create state what you do?
#sudo gitlab-runner verify   # user verify cmd to check if runner connected or not?
#$ gitlab-runner verify --delete -t Token-From-Your-Runner -u https://gitlab.com/  
also you can remove runner from below config file
/etc/gitlab-runner/config.toml

No comments:

Post a Comment