Running kubectl command from jenkins container Running kubectl command from jenkins container jenkins jenkins

Running kubectl command from jenkins container


It seems KUBECONFIG environment variable is not assigned to the correct config file.Therefore, you need to assign it first by following the command

export KUBECONFIG=~/.kube/config

Now kubectl can communicate with kube-api server. However, It needs to show its identity and capability to take actions on k8s resources, therefore, it will take client.crt and client.key files whenever it communicate with kube-api server. Now it can perform following tasks

kubectl apply -f deployment.yamlkubectl get podskubectl get nodes 

Solutions to your problem

Jenkins needs to have these certificate and keys in order to perform operations such as create, apply, get ,watch etc.


thank for your help, finaly i set cluster on jenkins and use --insecure-skip-tls-verify=true to avoid authentication as it's a test machine

kubectl config set-cluster minikube --server=https://127.0.0.1:8443 --insecure-skip-tls-verify=truekubectl config set-context minikube --cluster=minikube --user=minikubekubectl config use-context minikube 

And both container start on the same network