Skip to content

Connect a Kubernetes cluster to GitLab

To interact with a Kubernetes cluster during builds, deployments or other tasks in GitLab CI/CD, you need to install the GitLab agent on the cluster.

This operation is very easy with GitLab !

The official documentation is available here

Create a new cluster into GitLab

1 – In your project go to : Operate > Kubernetes Cluster and click on “Connect a Cluster”.

2 – Enter the name of the cluster and click register. The cluster name should follow the naming rules for Kubernetes ressources.

3 – Copy the code for the agent deployment and past it into your Kubernetes shell.

Questions about your own setup? A dbi services consultant can look at your case.

Talk to an expert (opens in a new tab)

Be sure to save the access token. It will be useful for upgrading the agent in the future.

4 – Verify deployment

The installation of the agent on the Kubernetes cluster creates a namespace gitlab-agent-[my cluster name]. This namespace contains the pod for the agent itself. When the pod is running, the status in the GitLab interface should change to “Connected”.

Conclusion

Installing the GitLab agent is really easy.

You can install several agents on the same project to connect several clusters (e.g. dev, test, prod).

Each cluster defined in GitLab creates a Kubernetes context for deployment in GitLab CI/CD.

To use it, see my next article about GitLab CI/CD deployment.

The same agent can be used by other projects to deploy on the same cluster. A configuration is required to allow other projects to use the agent.

Let’s work together

Ready to operate at
the next level?

Tell us about your challenge. We’ll bring the depth, the expertise, and the Swiss precision.

Nicolas Meunier

Nicolas Meunier

Nicolas Meunier specializes in cloud solutions and has more than 20 years of experience in IT web technologies and development, including CI/CD, Kubernetes, Docker, Jenkins-X, and Azure DevOps. Prior to dbi services, he developed and maintained a CI/CD pipeline at CEGID in Paris and worked as Lead Developer at KPMG. He holds a superior technical diploma in IT development. His background covers software and cloud platform architecture.View Author posts

21 posts since November 2022

Most read in Kubernetes

The Kubernetes posts our readers open most: the all-time favourites, and what is trending right now.

Leave a Comment

Your email address will not be published. Required fields are marked *