Integrate GitLab with Google Kubernetes Engine in 5 steps

Photo by Pankaj Patel on Unsplash

GitLab offers integration with Google Kubernetes Cluster and Amazon Elastic Kubernetes Services. To follow this article, you need a Google Kubernetes Cluster and GitLab account. I am sure you can obtain a GitLab account if you haven’t got one, and I have you covered with creating a GKE cluster in this article: Deploy WebApp using Google Kubernetes Engine.

So let’s get started.

Step 1: Add GKE cluster

In GitLab, go to side panel > Operations > Kubernetes > Integrate with a cluster certificate

Select Connect existing cluster > Google GKE

Step 2: Add Cluster information

Cluster name is an identifier for GitLab, so the name can be different from the GKE Cluster name. Leave environment scope with the wildcard, unless you wish to specify it, such as production or staging.

Step 3: Add API URL and Certificate

You can either perform this action from cloud CLI if you have the Cloud SDK installed, or go to your GKE cloud shell from your project. Get the API URL by running the following command:

In return, you will receive a base URL, either as a domain name: www.example.com or with IP address, add this API URL to your GitLab console.

Step 4: Add Kubernetes CA Certificate

First of all, list the secrets with command and copy the token which looks like default-token-abcdef:

Second, obtain the certificate with the following command:

Copy the certificate into your GitLab console, and bonus point by highlight the certificate from the command line, it automatically copies the content for you, please don’t select copy because it might also add line-break.

Step 5: Add Kubernetes CA Certificate

From your terminal, create a file called gitlab-admin-service-account.yaml

Copy following content into the file:

Save and quit the vi editor with the below command and click enter:

Apply the service account to your cluster:

You should see content from the terminal:

Obtain the token:

Copy the token value to GitLab console:

Add a project namespace prefix if you prefer a String name rather than random numbers. Click the blue-button and job done! ✅

Enthusiastic about cloud technology, data, clean code, Flutter, and Agile

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store