CI/CD with gitlab (online) to kubernetes cluster (kismatic)

8/23/2018

I have setup k8s cluster using kismatic and created CI/CD pipeline in gitlab. K8s cluster is in aws ec2 single instance. So how to connect gitlab with k8s cluster + helm to deploy the images.

-- GihanS
gitlab
gitlab-ci
kubectl
kubernetes
kubernetes-helm

1 Answer

8/23/2018

All newer versions of k8 have rbac enabled so the token runner will ultimately be using will have to be clusterbinding or you won't be able to deploy outside of the namespace of the token

1) If you use a runner with persistent state such as an ec2 instance then you can just copy over your working kubeconfig found in ~/.kube/config

2) You can deploy a runner into kubernetes. This is very simple, they have a helm chart for a runner. You'll need to clusterbind the service account the runner is deployed to, chart doesn't do it for you

3) If you're using their runners you can base64 kubeconfig into a CI variable and create the file as a before script

4) Integrate kubernetes the gitlab way (it's on the UI) then gitlab will inject a kubeconfig into jobs that have an environment section. This is what I'm doing, integration is a bit rough but if you would like to have feature branch sandbox deployments there's a way to have a stage to teardown after merge so it's quite nice however I'd skip their add-on buttons such as helm and ingress and do that myself instead as you don't get to tweak any options

Other than option 1; you then use a helm or kubectl image for your deploy jobs

-- Lev Kuznetsov
Source: StackOverflow