GitLab CI/CD implementation on Kubernetes Cluster (L4 And L7 Load Balancer)
- Login to Gitlab and create a project
2. Add Kubernetes cluster in created project
3. Add existing cluster and fill up all the fields which is related to kube-config file.
4. Disable the Auto Dev-Ops for project. Go to settings->CI/CD->Expand Auto Dev-Ops and uncheck the Default to Auto DevOps Pipeline.
5. Create or Enable Runner for this project (Settings->CI/CD->Expand Runner) . Set up a specific Runner manually or Enable the shared runner (https://vineetcic.medium.com/registering-gitlab-runners-2f78703d024e)(Created earlier by using link https://docs.gitlab.com/runner/install/linux-manually.html)
6. Now Deploy the project with Docker file, gitlab ci/cd file and kubernetes template file. Gitlab CI/CD file named .gitlab-ci.yml and format is as below
#before_script:
# - sudo usermod -aG docker $USER
build:
script:
- docker build -t dokcer.io/library/nginx:$CI_COMMIT_SHA .
- docker login -u $USER -p $PASSWORD docker.io
- docker push docker.io/library/nginx:$CI_COMMIT_SHA
deploy:
script:
- sed "s/_TAG_/$CI_COMMIT_SHA/g" kubernetes.tpl.yml > kubernetes.yml;
- sed 's/_SERVER_/$SERVER/g; s/_TOKEN_/$TOKEN/g' demo_tpl.yml > kubeconfig.yml; cat kubeconfig.yml
- kubectl --kubeconfig=kubeconfig.yml apply -f kubernetes.yml
7. Download gitlab CI/CD on Kubernetes cluster with L4 Load Balancer : https://gitlab.com/vineetkumar03/gitlab-cicd-l4lb and for L7 Load Balancer: https://gitlab.com/vineetkumar03/gitlab-cicd-l7lb
8. Set Environment variable for use encrypted parameters like password and token values (Like $USER ,$PASSWORD,$TOKEN etc.) in GitLab project: settings — > CI/CD — > Expand Variables and define variable and its value.