This is the 8th day of my participation in Gwen Challenge

This article describes how to add a K8S cluster to a Gitlab project so that we can use the K8S cluster to deploy gitLab-Runner to run Gitlab’s CI/CD for us.

Refer to the official documentation: docs.gitlab.com/ee/user/pro…

Locate the location for adding the data

Log in gitLab, enter your project home page, menu bar Operations => Kubernetes => Add Kubernetes Cluster, select TAB Add Existing Cluster.

We just need to get the value of the response and record it into the form. Kubernetes cluster name Specifies the cluster name. Leave the Project namespace blank.

Access to the API URL

Run the following command to get the output:

Kubernetes kubectl cluster - info | grep 'master' | awk '/ HTTP / {print $NF}' access to the CA CertificateCopy the code

Run the following command to get the output:

kubectl get secret $(kubectl get secret | grep default-token | awk '{print $1}') -o jsonpath="{['data']['ca\.crt']}" | Base64 -- Decode to obtain tokensCopy the code

Create file gitlab-admin-service-account.yaml:

The vim gitlab-admin-service-account.yaml file contains the following contents:

apiVersion: v1 kind: ServiceAccount metadata: name: gitlab-admin namespace: kube-system --- apiVersion: rbac.authorization.k8s.io/v1beta1 kind: ClusterRoleBinding metadata: name: gitlab-admin roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects: - kind: ServiceAccount name: gitlab-admin namespace: Kube-system run the following command to get the output:  kubectl apply -f gitlab-admin-service-account.yaml kubectl -n kube-system describe secret $(kubectl -n kube-system get Secret | grep gitlab - admin | awk '} {print $1) add finished, can be installed in the cluster you want to use the plug-in, such as gitlab - runner.Copy the code

When Kubernetes cluster is added to Gitlab, there may be a problem of compatibility between the two versions. This will cause Gitlab to fail to call THE API of K8S cluster. It may be because the API of different versions of K8S is updated. Try to use the latest version of Gitlab, it will support more versions of THE K8S API.

Can through the document view Gitlab support K8S version: docs.gitlab.com/ee/user/pro…