<p>I am trying to setup Jenkins Dynamic slaves creation using jenkins-kubernetes plugin.</p>

<p><strong>My jenkins is running outside K8s Cluster.</strong></p>

<p>Link: <a href="https://github.com/jenkinsci/kubernetes-plugin" rel="noreferrer">https://github.com/jenkinsci/kubernetes-plugin</a> </p>

<p>My jenkins version is <strong>2.60.2</strong> and Kubernetes plugin version is <strong>1.1.2</strong> </p>

<p>I followed the steps mention on the readme and successfully setup the connection.</p>

<p>My setting looks like:
<a href="https://i.stack.imgur.com/8dxSA.png" rel="noreferrer"><img src="https://i.stack.imgur.com/8dxSA.png" alt="enter image description here"></a></p>

<p>And connection is successful.</p>

<p>Then I created a job with pod template :
<a href="https://i.stack.imgur.com/bN0zV.png" rel="noreferrer"><img src="https://i.stack.imgur.com/bN0zV.png" alt="enter image description here"></a></p>

<p>Here starts the problem:
<strong>1. When I run this job initially it runs and jenkins slave container inside my pod not able to connect and throws:</strong></p>

<p><a href="https://i.stack.imgur.com/SDNrw.png" rel="noreferrer"><img src="https://i.stack.imgur.com/SDNrw.png" alt="enter image description here"></a></p>

<p>I have enabled JNLP port(50000) not sure if it is the right port even tested with random option in Jenkins nothing worked.</p>

<p><strong>2. Now I discarded this jenkins job and re run again it says:</strong></p>

<pre><code> Started by user Vaibhav Jain
[Pipeline] podTemplate
[Pipeline] {
[Pipeline] node
Still waiting to schedule task
Jenkins doesn’t have label defaultlabel
</code></pre>

<p>and no pod is getting started in kubernetes. <strong>This is weird</strong>.</p>

<p>I am not sure what I am doing wrong. 
Need help!</p>

<p>Instead of using certificates, I suggest you to use credentials in kubernetes, by creating a serviceAccount:</p>

<pre><code>---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: jenkins
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: jenkins
rules:
- apiGroups: [""]
  resources: ["pods"]
  verbs: ["create","delete","get","list","patch","update","watch"]
- apiGroups: [""]
  resources: ["pods/exec"]
  verbs: ["create","delete","get","list","patch","update","watch"]
- apiGroups: [""]
  resources: ["pods/log"]
  verbs: ["get","list","watch"]
- apiGroups: [""]
  resources: ["secrets"]
  verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: RoleBinding
metadata:
  name: jenkins
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: jenkins
subjects:
- kind: ServiceAccount
  name: jenkins
</code></pre>

<p>and deploying jenkins using that serviceAccount:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    app: jenkins
  name: jenkins
spec:
  replicas: 1
  selector:
    matchLabels:
      app: jenkins
  template:
    metadata:
      labels:
        app: jenkins
    spec:           
      serviceAccountName: jenkins 
....
</code></pre>

<p>I show you my screenshots for Kubernetes plugin (note Jenkins tunnel for the JNLP port, 'jenkins' is the name of my kubernetes service):</p>

<p><a href="https://i.stack.imgur.com/ohScK.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ohScK.png" alt="enter image description here"></a></p>

<p><a href="https://i.stack.imgur.com/f8ECq.png" rel="noreferrer"><img src="https://i.stack.imgur.com/f8ECq.png" alt="enter image description here"></a></p>

<p>For credentials:</p>

<p><a href="https://i.stack.imgur.com/Ti19f.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Ti19f.png" alt="enter image description here"></a></p>

<p>Then fill the fileds (ID will be autogenerated, description will be shown in credentials listbox), but be sure to have created serviceAccount in kubernetes as I said before:</p>

<p><a href="https://i.stack.imgur.com/iSFqX.png" rel="noreferrer"><img src="https://i.stack.imgur.com/iSFqX.png" alt="enter image description here"></a></p>

<p>My instructions are for the Jenkins master inside kubernetes. If you want it outside the cluster (but slaves inside) I think you have to use simple login/password credentials.</p>

<p>For what concerns your last error, it seems to be a host resolution error: the slave cannot resolve your host.</p>

<p>I hope it helps you.</p>
