GitLab:Kubernetes
lastmod 2025-02-14created 2022-12-094 edits
How to integrate k8s with GitLab, installing gitlab on k8s, etc. ...
Mainly intended for use in CI/CD.
Installing gitlab on k8s
Building a CI/CD environment using k8s with gitlab
- Building a CI/CD environment with k8s + GitLab - Horollihan Haru
- GitLab CI/CD tutorial
- Hansung's DevOps blog - Kubernetes & Gitlab Runner integration (.gitlab-ci.yml script)
- Kube-apiserver
Fill in the input fields as follows
- Kubernetes cluster name: enter any name
- Environment scope:
* - API URL:
https://{Masternode ip}:6443(HTTPS is correct!!) - CA Certificate: can be checked on the master node with the following command.
*
kubectl config view --raw \ -o=jsonpath='{.clusters[0].cluster.certificate-authority-data}' \ | base64 --decode
</syntaxhighlight>
- Service Token: before getting the service token, you need to create a service account for GitLab to use.
- A service token scoped to kube-system with cluster-admin privileges. More information
*
- gitlab-admin.yaml
apiVersion: v1 kind: ServiceAccount metadata:
name: gitlab-adminnamespace: kube-system
--- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata:
name: gitlab-admin
roleRef:
apiGroup: rbac.authorization.k8s.iokind: ClusterRolename: cluster-admin
subjects: - kind: ServiceAccount
name: gitlab-adminnamespace: kube-system
</syntaxhighlight>
-
- After saving, run it as follows:
$ kubectl apply -f gitlab-admin.yaml serviceaccount/gitlab-admin unchanged clusterrolebinding.rbac.authorization.k8s.io/gitlab-admin created
</syntaxhighlight>
Problems
- Configure Service Accounts for Pods | Kubernetes # Manually create an API token for a ServiceAccount
The token cannot be obtained.
Troubleshooting
no matches for kind "ClusterRoleBinding" in version "rbac.authorization.k8s.io/v1beta1"
If you get the following error when running kubectl apply -f gitlab-admin.yaml:
serviceaccount/gitlab-admin created
error: resource mapping not found for name: "gitlab-admin" namespace: "" from "gitlab-admin.yaml": no matches for kind "ClusterRoleBinding" in version "rbac.authorization.k8s.io/v1beta1"
ensure CRDs are installed first
If you set the apiVersion of ClusterRoleBinding to rbac.authorization.k8s.io/v1beta, change it to rbac.authorization.k8s.io/v1 for it to work properly.