Skip to content

Instantly share code, notes, and snippets.

@davistran86
Forked from hardyscc/gitlab-microk8s.md
Created October 12, 2021 15:09
Show Gist options
  • Save davistran86/171fb71e1323552812d4054b8505aa46 to your computer and use it in GitHub Desktop.
Save davistran86/171fb71e1323552812d4054b8505aa46 to your computer and use it in GitHub Desktop.
Gitlab MicroK8s CI/CD Integration

Gitlab MicroK8s CI/CD Integration

Install microk8s

sudo snap install microk8s --classic
sudo microk8s status --wait-ready

Install plugins

sudo microk8s enable dns ingress rbac storage

Switch to use kubectl

sudo snap install kubectl helm --classic
mkdir ~/.kube
sudo microk8s config > ~/.kube/config
chmod 600 ~/.kube/config

Add your domain as follow

sudo sed -i '/DNS.5/a \
DNS.6 = api.yourdomain.com' /var/snap/microk8s/current/certs/csr.conf.template

Config DNS

  • A-Record : yourdomain.com > <YOUR_IP_ADDRESS>
  • Alias (CNAME) : api.yourdomain.com > yourdomain.com
  • Alias (CNAME) : *.apps.yourdomain.com > yourdomain.com

Config Port Forward

  • 80
  • 443
  • 16443

Gitlab setup

  • Kubernetes cluster name : microk8s-cluster
  • API URL : https://api.yourdomain.com:16443
  • Base Domain : apps.yourdomain.com

Get the CA Certificate

kubectl get secret $(kubectl get secret | grep default-token | awk '{print $1}') -o jsonpath="{['data']['ca\.crt']}" | base64 --decode

Get the Service Token

kubectl -n kube-system create serviceaccount gitlab
kubectl create clusterrolebinding gitlab-admin --clusterrole=cluster-admin --serviceaccount=kube-system:gitlab
kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep gitlab | awk '{print $1}')

Finally install Gitlab Runner and Cert-Manager under Applications tab page

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment