Skip to content

Gitlab K8S Agent support

Description

The Gitlab K8S Agent introduced in GitLab 14.1 change the way KUBECONFIG is injected in the CI/CD pipeline. Projects have to explicitely select the right KUBE_CONTEXT before interacting with K8S.

All CI/CD jobs now include a KUBECONFIG with contexts for every shared agent connection. Choose the context to run kubectl commands from your CI/CD scripts.

https://docs.gitlab.com/ee/user/clusters/agent/

Implementation ideas

The Kubernetes templates already detects when the KUBECONFIG is originated from Gitlab. We can just switch to the right KUBE_CONTEXT if presents.

NOTE : We might think the Helm template has the same problem. However we have a workaround using the $HELM_KUBECONTEXT environment property.