<p>I'm begginer in Kubernetes and trying to deploy Jenkins in a cluster, but the pod is getting pending.</p>

<p>I need jenkins with access to kubernetes, including access to docker and kubectl commands, for continuos integration with my microservices.</p>

<p>With this example yaml file, I can start a jenkins instance on a local machine (my notebook) through Minikube.</p>

<p>But now I'm trying to use a cloud cluster as part of my field of study.</p>

<p>I accept suggestions for improvements.</p>

<p>As I said: I just want to upload an instance of jenkins, with which I can continually integrate my micro services.</p>

<p>These are my configs and logs.</p>

<p>What is my mistake?</p>

<pre><code>apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: jenkins-rbac
subjects:
  - kind: ServiceAccount
    name: default
    namespace: default
roleRef:
  kind: ClusterRole
  name: cluster-admin
  apiGroup: rbac.authorization.k8s.io
---
kind: PersistentVolume
apiVersion: v1
metadata:
  name: jenkins
  labels:
    type: local
spec:
  capacity:
    storage: 2Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/data/jenkins/"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: jenkins-claim
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 2Gi
---
apiVersion: v1
kind: Service
metadata:
  name: jenkins
  labels:
    app: jenkins
spec:
  ports:
    - port: 80
      targetPort: 8080
      nodePort: 32256
  selector:
    app: jenkins
    tier: jenkins
  type: NodePort
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: jenkins
  labels:
    app: jenkins
spec:
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: jenkins
        tier: jenkins
    spec:
      containers:
      - image: sammubr/jenkins
        name: jenkins
        securityContext:
          privileged: true
        ports:
        - containerPort: 8080
          name: jenkins
        volumeMounts:
        - name: jenkins-persistent-storage
          mountPath: /var/jenkins_home
        - name: docker
          mountPath: /var/run/docker.sock
      volumes:
      - name: docker
        hostPath:
          path: /var/run/docker.sock
      - name: jenkins-persistent-storage
        persistentVolumeClaim:
          claimName: jenkins-claim
</code></pre>

<p>Then <code>kubectl --context do-sfo2-teste-cluster apply -f jenkins.yaml</code></p>

<p>But is allways pending:</p>

<pre><code>samuel@samuel-Inspiron-5548:~/Documentos/teste/jenkins$ kubectl get all
NAME                           READY   STATUS    RESTARTS   AGE
pod/jenkins-5dc7fbd78d-9wxfl   0/1     Pending   0          8m34s

NAME                 TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
service/jenkins      NodePort    10.245.30.47   &lt;none&gt;        80:32256/TCP   8m34s
service/kubernetes   ClusterIP   10.245.0.1     &lt;none&gt;        443/TCP        79m

NAME                      READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/jenkins   0/1     1            0           8m35s

NAME                                 DESIRED   CURRENT   READY   AGE
replicaset.apps/jenkins-5dc7fbd78d   1         1         0       8m35s
</code></pre>

<pre><code>samuel@samuel-Inspiron-5548:~/Documentos/teste/jenkins$ kubectl describe pod/jenkins-5dc7fbd78d-9wxfl
Name:               jenkins-5dc7fbd78d-9wxfl
Namespace:          default
Priority:           0
PriorityClassName:  &lt;none&gt;
Node:               &lt;none&gt;
Labels:             app=jenkins
                    pod-template-hash=5dc7fbd78d
                    tier=jenkins
Annotations:        &lt;none&gt;
Status:             Pending
IP:                 
Controlled By:      ReplicaSet/jenkins-5dc7fbd78d
Containers:
  jenkins:
    Image:        sammubr/jenkins
    Port:         8080/TCP
    Host Port:    0/TCP
    Environment:  &lt;none&gt;
    Mounts:
      /var/jenkins_home from jenkins-persistent-storage (rw)
      /var/run/docker.sock from docker (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-5wdgs (ro)
Conditions:
  Type           Status
  PodScheduled   False 
Volumes:
  docker:
    Type:          HostPath (bare host directory volume)
    Path:          /var/run/docker.sock
    HostPathType:  
  jenkins-persistent-storage:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  jenkins-claim
    ReadOnly:   false
  default-token-5wdgs:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-5wdgs
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  &lt;none&gt;
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason            Age               From               Message
  ----     ------            ----              ----               -------
  Warning  FailedScheduling  7s (x8 over 10m)  default-scheduler  pod has unbound immediate PersistentVolumeClaims (repeated 2 times)
</code></pre>

sammubr
<p>As @ortomala-lokni mentioned earlier, you are having an issue with unbound PersistentVolumeClaims to the declared before PersitanceVolume, which causes eventually the Jenkins Pod unable to start up. <br><br>In the shared <a href="https://stackoverflow.com/questions/52668938/pod-has-unbound-persistentvolumeclaims">link</a> by @ortomala-lokni to the similar question on SO, one can read about various reasons of this error, and how to fix them.</p>

<p>In your particular case the mismatch between what PVC's demands and PV provisioned actually on your cluster, is in accessModes (ReadWriteOnce vs. ReadWriteMany).</p>

<p><strong>To fix</strong> your problem please update the 'PersistentVolumeClaim' definition accordingly, should look like this:</p>

<pre><code>kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: jenkins-claim
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi
</code></pre>

<p><strong>Note:</strong><br>
You don't need '<a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes" rel="nofollow noreferrer">ReadWriteMany</a>' access mode with single replica of Jenkins Pod. This is because with current definition of your 'jenkins' Deployment, under the hood the Deployment controller creates a ReplicaSet object, which by default ensures that only single instance of Jenkins Pod is running (= simplifying only single instance of Jenkins server will be writing to this volume at once).</p>

<p>Please find <a href="https://github.com/GoogleCloudPlatform/continuous-deployment-on-kubernetes/tree/320bf7b11cc3f4f9d74fe26a173f886574e2ef2f" rel="nofollow noreferrer">here</a> another tutorial on setting up Jenkins on Kubernetes from scratch, using helm (recommended way).</p>
