kubeconfig into a GitLab CI pipeline so that kubectl can authenticate and interact with your cluster. This setup is essential for automated deployments, health checks, and infrastructure management within your CI/CD workflows.
Why You Need to Provide a Kubeconfig
Whenkubectl runs without a valid kubeconfig, it can only display client information and will fail to contact the API server:
kubeconfig, kubectl cannot reach your cluster’s API endpoint.
Local vs. CI: Kubernetes Authentication
On Your Local Machine
With a valid~/.kube/config, you will see both client and server versions:
kubeconfig might look like this:
Storing Kubeconfig in GitLab CI/CD
To securely pass yourkubeconfig into CI jobs, add it as a File-type variable in your project’s CI/CD Settings:

Treat your
kubeconfig as sensitive data. File variables are stored encrypted, but avoid exposing them in job logs or unsecured scopes.Updating the CI Job to Use Kubeconfig
Modify your.gitlab-ci.yml job to export the KUBECONFIG environment variable from the File variable before invoking any kubectl commands:
k8s_dev_deploy job should now complete successfully:
