<p>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</p>
<blockquote>
<p>Error connecting to <a href="https://192.168.X.XX:6443" rel="nofollow noreferrer">https://192.168.X.XX:6443</a>: Failure executing: GET at: <a href="https://192.168.X.XX:6443/api/v1/namespaces/default/pods" rel="nofollow noreferrer">https://192.168.X.XX:6443/api/v1/namespaces/default/pods</a>. Message: User &quot;system:anonymous&quot; cannot list pods in the namespace &quot;default&quot;..&quot;</p>
</blockquote>
<p>I tried to perform curl with --insecure option but the same following error is logged.</p>
<blockquote>
<p>Message: User &quot;system:anonymous&quot; cannot list pods in the namespace &quot;default&quot;..&quot;</p>
</blockquote>
<p>I tried to add jenkins and the user credentials to login to jenkins as clusteradminrole using the following kubectl command</p>
<blockquote>
<p>kubectl create rolebinding jenkins-admin-binding --clusterrole=admin --user=jenkins--namespace=default</p>
</blockquote>
<p>But still the same error.</p>
<p>Anything is missing?</p>
<p>EDIT 1: Have tried to do the following as suggested</p>
<blockquote>
<p>openssl genrsa -out jenkins.key 2048</p>
<p>openssl req -new -key  jenkins.key -out jenkins.csr -subj &quot;/CN=jenkins/O=admin_jenkins&quot;</p>
<p>openssl x509 -req -in jenkins.csr -CA /etc/kubernetes/pki/ca.crt -CAkey /etc/kubernetes/pki/ca.key -CAcreateserial -out jenkins.crt -days 500</p>
<p>kubectl config set-credentials jenkins --client-certificate=/root/pods/admin_jenkins/.certs/jenkins.crt --client-key=/root/pods/admin_jenkins/.certs/jenkins.key</p>
<p>kubectl config set-context jenkins-context --cluster=kubernetes --namespace=default --user=jenkins</p>
<p>kubectl create -f role.yaml (Role file as described)</p>
<p>kubectl create -f role-binding.yaml</p>
</blockquote>
<p>even after this</p>
<pre><code>kubectl --context=jenkins-context get deployments 
gives the following error
&quot;Error from server (Forbidden): User &quot;jenkins&quot; cannot list deployments.extensions in the namespace &quot;default&quot;. (get deployments.extensions)&quot;
</code></pre>
<p>Update 2:</p>
<pre><code>after following above steps 
&quot;kubectl --context=jenkins-context get deployments&quot; was successful.

 i did the whole exercise after doing a kubeadm reset and it worked
</code></pre>
<p>But the problem still remains of integrating K8 with Jenkins when i am trying to add it as a cloud using its plugin.</p>

<p>Did you define the role <code>admin</code>? if not define the admin role. below document your refer it.</p>

<p><a href="https://docs.bitnami.com/kubernetes/how-to/configure-rbac-in-your-kubernetes-cluster/" rel="nofollow noreferrer">https://docs.bitnami.com/kubernetes/how-to/configure-rbac-in-your-kubernetes-cluster/</a></p>

<p>Update:
1. you can create file <code>role.yaml</code> like this and create role. then run <code>kubectl apply -f role.yaml</code></p>

<pre><code> kind: Role
  apiVersion: rbac.authorization.k8s.io/v1beta1
  metadata:
    namespace: default
    name: admin
  rules:
  - apiGroups: ["", "extensions", "apps"]
    resources: ["deployments", "replicasets", "pods"]
    verbs: ["get", "list", "watch", "create", "update", "patch", "delete"] # You can also use ["*"]
</code></pre>

<p>you need to pass the client certificate with this role to authenticate. </p>

<p>from your second question your trying to use this account to authenticate jenkin application user. I am not sure this method will work for you.</p>

<p><strong>update on 9/25/17</strong></p>

<pre><code>Username: admin
Group: jenkins


 openssl genrsa -out admin.key 2048
 openssl req -new -key admin.key -out admin.csr -subj "/CN=admin/O=jenkins"

 #Run this as root user in master node
 openssl x509 -req -in admin.csr -CA /etc/kubernetes/pki/ca.crt  -CAkey /etc/kubernetes/pki/ca.key -CAcreateserial -out admin.crt -days 500

 mkdir .certs/
 mv admin.* .certs/
 kubectl config set-credentials admin --client-certificate=/home/jenkin/.certs/admin.crt  --client-key=/home/jenkin/.certs/admin.key
 kubectl config set-context admin-context --cluster=kubernetes --namespace=jenkins --user=admin 
</code></pre>

<p><strong>Save this in the file and create role</strong></p>

<pre><code>kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  namespace: jenkins
  name: deployment-manager
rules:
- apiGroups: ["", "extensions", "apps"]
  resources: ["deployments", "replicasets", "pods"]
  verbs: ["get", "list", "watch", "create", "update", "patch", "delete"] # You can also use ["*"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: deployment-manager-binding
  namespace: jenkins
subjects:
- kind: User
  name: admin
  apiGroup: ""
roleRef:
  kind: Role
  name: deployment-manager
  apiGroup: ""
</code></pre>

<p><strong>Run the get pods command</strong></p>

<pre><code>kubectl --context=admin-context get pods
</code></pre>
