title: How to configure Jenkins master and dynamic agents in different clouds? With Kubernetes plugin
body: <p>For context, I work at a large company with teams in different clouds (Azure and IBM cloud formerly Bluemix). The Ops team will have control of Jenkins master eventually, but since my team is the first needing this, we are setting it up.</p>
  
  <p>What we have:</p>
  
  <ul>
  <li>Jenkins master is in Azure (<strong>cloud A</strong>), latest version, and we have the Kubernetes plugin (among others) to have dynamic provisioning of agents. </li>
  <li>My team works in IBM Kubernetes clusters (<strong>cloud B</strong>). In this cloud, we have a namespace for devops in a cluster of k8s, where we want the slave agents to be created and run. In this cloud we also created a service accounts in that namespace, a role, and rolebinding.</li>
  </ul>
  
  <p>Problem: Configuring Jenkins master to connect with such namespace in IBM cloud to provision agents and run the jobs as needed. 
  Especifically, in Jenkins > Manage > COnfigure System > Cloud.
  Here I have:</p>
  
  <ul>
  <li>Kubernetes URL set to the IP:port of the master node of the cluster</li>
  <li>Kubernetes server certificate key, I put here the certificate I got when I created the service account.</li>
  <li>Namespace, Credentials I have the service account and finally the Jenkins URL.</li>
  </ul>
  
  <p>When I try that configuration, and test the connection I get: </p>
  
  <blockquote>
    <p>Error testing connection <a href="https://ip:port" rel="nofollow noreferrer">https://ip:port</a>: Failure executing: GET at:
    <a href="https://ip:port/api/v1/namespaces/devops/pods" rel="nofollow noreferrer">https://ip:port/api/v1/namespaces/devops/pods</a>. Message: Unauthorized!
    Configured service account doesn't have access. Service account may
    have been revoked. Unauthorized.</p>
  </blockquote>
  
  <p>Questions:</p>
  
  <ul>
  <li>Anybody knows how to do this or has links to something similar? </li>
  <li>In the image, what should I put in kubernetes URL? According to the docs, I should enter the container engine cluster endpoint, what is that in IBM Cloud? I have the IP and port of the Master node.</li>
  </ul>
  
  <p>I´ve read a lot of documentation from IBM, the kubernetes plugin for Jenkins (<a href="https://github.com/jenkinsci/kubernetes-plugin" rel="nofollow noreferrer">https://github.com/jenkinsci/kubernetes-plugin</a>) and tons of other posts explaining how to configure jenkins with kubernetes and dynamic provisioning and many of them said it is possible to have jenkins and the slaves in different clouds, but none of them explained how to do it..</p>
  
  <p>Thank you in advance.</p>
  
  <p>++++++++++++++++++ UPDATE +++++++++++++++++++++++</p>
  
  <p>In the following screenshot I show the configurations that I am using. In particular, the fields <strong>Kubernetes URL</strong> and <strong>namespace</strong>. </p>
  
  <p>Thanks to @samhain1138 for his help so far, but <strong>I cannot get a connection test successful</strong> in the Jenkins Kubernetes plugin configuration section. I think I may not be entering the correct info in some of the fields in that section.</p>
  
  <p>Note: Please keep in mind that my setup is as follows: Jenkins master is in Cloud A (Azure) and I want the agent nodes to run is in a different cluster in another cloud, call it Cloud B (which in my case is IBM Cloud).</p>
  
  <p><a href="https://i.stack.imgur.com/zi7ug.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zi7ug.png" alt="enter image description here"></a></p>
  
  <p>In the screenshot above I am certain that I have the correct values for the <strong>Kubernetes URL</strong> and <strong>namespace</strong>, but I am unsure about the other fields (<strong>Kubernetes server certificate key</strong> and <strong>Credentials</strong>.) </p>
  
  <p>In the <strong>Kubernetes server certificate key</strong> field I tried putting:</p>
  
  <ul>
  <li>The ca.cert of the Service Account in the kubernetes cluster in IBM. (Obtained by 1. creating service account, getting the secret of that service account, and extracting the ca.cert from such secret)</li>
  <li>The "Token" from the server, which I get doing a kubectl config view in the kubernetes cluster in IBM. The token is in the field users>user>auth-provider>config>id-token when you execute the command "kubectl config view"</li>
  </ul>
  
  <p>In Credentials I created and tried different <strong>Kinds</strong>:</p>
  
  <ul>
  <li>Username and Password: I tried this with my credentials for the IBM cluster and with the service account credentials (When I created the service account, role, and role-binding, I noticed that user was created which was serviceaccountname-namespace-cluster)</li>
  <li>Kubernetes Service Account </li>
  </ul>
  
  <p>I tried all the combinations of those, and could never get <strong>Connection Successful when Testing the Connection</strong>. </p>
  
  <p>Erros I get:</p>
  
  <ul>
  <li><p>Error testing connection <a href="https://APISERVER" rel="nofollow noreferrer">https://APISERVER</a>: Failure executing: GET at: <a href="https://APISERVER/api/v1/namespaces/a-devops-namespace/pods" rel="nofollow noreferrer">https://APISERVER/api/v1/namespaces/a-devops-namespace/pods</a>. Message: Unauthorized! Configured service account doesn't have access. Service account may have been revoked. Unauthorized.</p></li>
  <li><p>Error testing connection <a href="https://APISERVER" rel="nofollow noreferrer">https://APISERVER</a>: Failure executing: GET at: <a href="https://APISERVER/api/v1/namespaces/a-devops-namespace/pods" rel="nofollow noreferrer">https://APISERVER/api/v1/namespaces/a-devops-namespace/pods</a>. Message: Forbidden!Configured service account doesn't have access. Service account may have been revoked. pods is forbidden: User "system:anonymous" cannot list pods in the namespace "a-devops-namespace".</p></li>
  </ul>