kubectl error: error loading config file "/var/lib/jenkins/.kube/config":

7/17/2020

I am configuring Jenkins to automatically deploy my successfull builds to my Kubernetes cluster. I have manually set up the KUBECONFIG file in /var/lib/jenkins/.kube/config.

But my Jenkins job keeps giving the same error:

+ kubectl config --kubeconfig=/var/lib/jenkins/.kube/config view
error: error loading config file "/var/lib/jenkins/.kube/config": v1.Config.Contexts: \
[]v1.NamedContext: Clusters: []v1.NamedCluster: v1.NamedCluster.Name: Cluster: v1.Cluster.Server: \
CertificateAuthorityData: decode base64: illegal base64 data at input byte 47, error found in #10 byte of ... \
|ASXY9gkN$","server":|..., bigger context ...|"LS3tGS1PR0dJTiBDRVJUMLPAR0FURS0tLS0tCk1JSUV5gkN$", \
"server":"https://clsx-cloud-d734ef-0b|...

I copied the kube config file manually from my SSH accessible account, i.e

cat home/username/.kube/config
-- marcuse
continuous-deployment
jenkins
kubectl
kubernetes

2 Answers

3/4/2021

I have fixed this error by removing files in this directory:

/var/lib/jenkins/.kube/

Note: take backup on first priority of this directory as well.

-- Muhammad Jamee Ghouri
Source: StackOverflow

7/17/2020

You most likely copied the wrong screen output from the terminal, or while editing the file in i.e nano.

The $ characters are illegal characters and the result of truncated file viewing in the terminal, make sure that you copy the real file data correctly.

For example:

xclip -sel clip < home/username/.kube/config
-- marcuse
Source: StackOverflow