Container registry for Kubernetes with GitLab

This article is more than 5 years old.


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.

kubernetes logo

What is Kubernetes?

Kubernetes, or K8s for short, is an open source platform pioneered by Google, which started as a simple container orchestration tool but has grown into a platform for deploying, monitoring and managing apps and services across clouds.

Learn more about Kubernetes ›

Newsletter signup

Get the latest Ubuntu news and updates in your inbox.

By submitting this form, I confirm that I have read and agree to Canonical's Privacy Policy.

Related posts

Meet Canonical at KubeCon + CloudNativeCon North America 2024

We are ready to connect with the pioneers of open-source innovation! Canonical, the force behind Ubuntu, is returning as a gold sponsor at KubeCon +...

How to use Ubuntu in GKE on nodes and in containers

Google Kubernetes Engine (GKE) traces its roots back to Google’s development of Borg in 2004, a Google internal system managing clusters and applications. In...

Kubernetes backups just got easier with the CloudCasa charm from Catalogic

For a native integration for Canonical’s Kubernetes platform, Juju was the perfect fit, and the charm makes consuming CloudCasa seamless for users.