Your submission was sent successfully! Close

  1. Blog
  2. Article

Peter Jose De Sousa
on 8 October 2019

Container registry for Kubernetes with GitLab


Container orchestration solutions such as Kubernetes allow development teams to be quick and agile with their software deployments.

One of the main features of Kubernetes is the ability to reduce the deployment of version piece of software down to a simple image tag which can be applied at the end of a command.” – said Tytus Kurek, Product Manager for Charmed Kubernetes at Canonical.

This opens the doors to streamlined deployments but creates another problem. How do we streamline? We can do this manually, but it’s not very streamlined. Or we can do this automatically, but we need to be smart. We can’t just deploy as soon as a new version is released. We need to check it first. This is where a container registry and CI/CD come in.

Prerequisites

Before we get started, we have to find ourselves a healthy Kubernetes cluster. Canonical offers both Charmed Kubernetes and MicroK8s solutions which are fully compliant with the upstream Kubernetes project. While Charmed Kubernetes is suitable for large-scale deployments in data centers or public clouds, MicroK8s was designed for workstation and edge appliances. You can install MicroK8s on your laptop at no cost by following this quick tutorial. If you’re on Windows or Mac you may need to follow the Multipass guide first to get a VM with Ubuntu.

Apart from Kubernetes, we will also need GitLab – a web-based DevOps lifecycle tool. GitLab has the ability to store up to 10 GB in a container registry for projects. You can incorporate the building of these containers into your own CI/CD pipeline or you can use Gitlab’s own CI/CD functionality to do this for you.

Setting up the container registry

Creating the container registry on GitLab involves completing the following steps:

  • Create a project – you can create a new project or use an existing one.
  • Create a Dockerfile – create a Dockerfile for an image to be built and stored in GitLab.
  • Enable Container Registry – enable Container Registry feature in GitLab’s settings.
  • Build an image – build an image from the Dockerfile; make sure you can successfully launch a container from this image.
  • Push the image – push the image to the project’s repository in GitLab.
  • Create a token – create a token that will be used by Kubernetes when pulling the image from GitLab.
  • Pull the image – at this point, you can start using images stored in GitLab when creating deployments in Kubernetes.

This is now as simple as executing the following command:

kubectl create deployment gitlabrepositories --image=registry.gitlab.com/<YOUR_USERNAME>/gitlabregistries

As the whole process requires a bunch of manual steps, we decided to create a detailed tutorial that you can follow step-by-step to get your container registry for Kubernetes created in GitLab.

Take The Tutorial

Conclusions

Using GitLab as a container registry for Kubernetes allows you to streamline your application deployments. You can check out GitLab’s documentation on how to take your newly learned skills and apply them to your own CI/CD or create one in GitLab.

Related posts


Valentin Viennot
9 January 2023

Chiselled Ubuntu containers: the benefits of combining Distroless and Ubuntu

Cloud and server Article

Last August, we announced 6 MB-size Ubuntu base images designed for self-contained .NET applications — we called them “chiselled Ubuntu”. How did we make our Ubuntu base images 15 times smaller? And how can you create your own chiselled Ubuntu images? In this blog, I explain the idea behind Distroless container images, which inspired us ...


Hugo Huang
29 November 2023

Generative AI explained

AI Article

When OpenAI released ChatGPT on November 30, 2022, no one could have anticipated that the following 6 months would usher in a dizzying transformation for human society with the arrival of a new generation of artificial intelligence. Since the emergence of deep learning in the early 2010s, artificial intelligence has entered its third wave ...


Canonical
21 November 2023

Canonical announces the general availability of chiselled Ubuntu containers

Canonical announcements Article

Production-ready, secure-by-design, ultra-small containers with chiselled Ubuntu Canonical announced today the general availability of chiselled Ubuntu containers which come with Canonical’s security maintenance and support commitment. Chiselled Ubuntu containers are ultra-small OCI images that deliver only the application and its runtime ...