GitLab Container Registry for CI/CD and Seamless Deployment

DevOps Engineer | Kubernetes | Python | Terraform | AWS | GCP
Search for a command to run...

DevOps Engineer | Kubernetes | Python | Terraform | AWS | GCP
No comments yet. Be the first to comment.
Tired of shuffling USB cables every time someone in your household or small office needs to print? Wish you could print wirelessly from any device on your network? Well, you're in luck! With the magic of a Raspberry Pi and a few simple commands, you ...

It is quite common to lose the integrity of configmaps/secrets for the following reasons: You have a large team with more than 5 people You do not use any Config/Secret Management Tool Lack of team collaboration Anyway, that's not the point. All...

It's quite common to see your important service account being modified by someone. Don't worry, my friend. Here is how you can track who did what. Login to GCP and navigate to Logging Set a proper timeline from the date-time picker (last X hour or ...

You can speed up your smart tv experience by disabling some annoying, built in apps. First, enable ADB on your Android TV unit. To Activate Developer Options: Navigate to Settings > About. Tap Build number seven times to enable developer mode. Once d...

If you need to automate the process of clicking a button on a webpage using Selenium, this guide will walk you through it effortlessly. Prerequisites You will need the following items. Python3 with selenium module Chrome Browser and Chrome Driver [...

GitLab is an excellent SaaS tool for storing your code and automating workflows. If you have a managed Kubernetes cluster, you can also use GitLab as the container registry and the CI/CD platform.
First, you need to create a permanent Access Token from your GitLab repository or group that will have access to all the child repositories and the container registry. This token will be used by kubelet to pull images from the GitLab-managed container registry. The secret creation will look like the following.
kubectl create secret docker-registry gitlab-token-auth \
--docker-server=https://registry.gitlab.com \
--docker-username=kubelet \
--docker-password=1234zxcv0987
If you trigger a GitLab workflow inside GitLab-hosted runners, the workflow will have the privilege to push container images into the same code repository. Built-in variables like CI_REGISTRY_USER, CI_REGISTRY_PASSWORD, and CI_REGISTRY_IMAGE will be automatically populated during the pipeline run. Here is the code snippet that needs to be added to push the newly built image into Gitlab's container registry.
push:
image: docker:24
services:
- docker:24-dind
stage: push
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build . -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
Once the image is pushed into Gitlab registry, you can use the previosly created Secret to pull the image into Kubernetes and run it. You will need to patch your deployment to include the imagePullSecrets.
spec:
metadata:
spec:
containers:
- name: app
image: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
imagePullSecrets:
- name: gitlab-token-auth