Integrate GitLab and kubernetes

This page covers integrating GitLab with kubernetes cluster to automatically deploy from GitLab to kubernetes via CI/CD jobs.

  1. In your project, go to Operate -> Kubernetes clusters, click the dropdown in the top right and select Connect a cluster (certificate - deprecated)
  2. In the namespace create a gitlab service account: kubectl create sa gitlab -n <your_namespace>
  3. Create the rolebinding for the service account:

    kubectl create -f - << EOF
    kind: RoleBinding
      name: gitlab
      namespace: <your_namespace>
      kind: ClusterRole
      name: admin
    - kind: ServiceAccount
      name: gitlab
      namespace: <your_namespace>
  4. Create a secret for the service account:

    kubectl -n <your_namespace> apply -f - << EOF
    apiVersion: v1
    kind: Secret
      name: gitlab-secret
      annotations: gitlab
  5. Get the secret and CA for the service account:

    kubectl get secret -n your_namespace | grep gitlab

    kubectl get secret -n your_namespace <gitlab-secret-...> -o yaml

    echo <the token value> | base64 -d - this will give you the service token field value

    echo <the CA value> | base64 -d - CA

    API URL - get from your cluster config file (

  6. Uncheck GitLab-managed cluster, enter the namespace into Project namespace prefix (optional, unique)

  7. Click Add kubernetes cluster

Now your cluster config will be available to tools like kubectl and helm to access your namespace. You can use this project as an example of how to automatically deploy a helm application yo your namespace and this one to automatically update the deployment image.