I am trying to add Kubernetes as cloud to Jenkins server with the appropriate Kubernetes URL and other details. When i add the details and test the connection i get the following error
Error connecting to https://192.168.X.XX:6443: Failure executing: GET at: https://192.168.X.XX:6443/api/v1/namespaces/default/pods. Message: User "system:anonymous" cannot list pods in the namespace "default".."
I tried to perform curl with --insecure option but the same following error is logged.
Message: User "system:anonymous" cannot list pods in the namespace "default".."
I tried to add jenkins and the user credentials to login to jenkins as clusteradminrole using the following kubectl command
kubectl create rolebinding jenkins-admin-binding --clusterrole=admin --user=jenkins--namespace=default
But still the same error.
Anything is missing?
EDIT 1: Have tried to do the following as suggested
openssl genrsa -out jenkins.key 2048
openssl req -new -key jenkins.key -out jenkins.csr -subj "/CN=jenkins/O=admin_jenkins"
openssl x509 -req -in jenkins.csr -CA /etc/kubernetes/pki/ca.crt -CAkey /etc/kubernetes/pki/ca.key -CAcreateserial -out jenkins.crt -days 500
kubectl config set-credentials jenkins --client-certificate=/root/pods/admin_jenkins/.certs/jenkins.crt --client-key=/root/pods/admin_jenkins/.certs/jenkins.key
kubectl config set-context jenkins-context --cluster=kubernetes --namespace=default --user=jenkins
kubectl create -f role.yaml (Role file as described)
kubectl create -f role-binding.yaml
even after this
kubectl --context=jenkins-context get deployments
gives the following error
"Error from server (Forbidden): User "jenkins" cannot list deployments.extensions in the namespace "default". (get deployments.extensions)"
Update 2:
after following above steps
"kubectl --context=jenkins-context get deployments" was successful.
i did the whole exercise after doing a kubeadm reset and it worked
But the problem still remains of integrating K8 with Jenkins when i am trying to add it as a cloud using its plugin.