<p>I have deployed my Jenkins as part of kubernetes yaml file and also enabled Persist volume claim, when my Jenkins pod is restarts, i lost my all the jobs and configuration which means i need to re-install all Jenkins suggest plugin, configure kubernetes cloud, configure git repo, and create new pipeline job.</p>
<p>cloud you please help me how to avoid above scenario.</p>
<p>vi jenkins-deployment.yaml</p>
<pre><code>kind: Deployment
apiVersion: apps/v1
metadata:
  name: jenkins-master
  namespace: jenkins
  labels:
    app: jenkins-master
spec:
  replicas: 1
  selector:
    matchLabels:
      app: jenkins-master
  template:
    metadata:
      labels:
        app: jenkins-master
    spec:
      securityContext:
        fsGroup: 1000
      containers:
      - name: jenkins
        image: jenkins/jenkins:lts
        imagePullPolicy: Always
        ports:
        - containerPort: 8080
        - containerPort: 50000
        readinessProbe:
          httpGet:
            path: /login
            port: 8080
          initialDelaySeconds: 300
          periodSeconds: 10
          timeoutSeconds: 5
          successThreshold: 2
          failureThreshold: 5
        volumeMounts:
        - mountPath: &quot;/var&quot;
          name: jenkins-home
          subPath: jenkins_home
        resources:
          limits:
            cpu: 800m
            memory: 3Gi
          requests:
            cpu: 100m
            memory: 3Gi
      volumes:
      - name: jenkins-home
        persistentVolumeClaim:
          claimName: pvc-jenkins-home
</code></pre>
<p>vi jenkins-pvc.yaml</p>
<pre><code>kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: pvc-jenkins-home
  namespace: jenkins
spec:
  storageClassName: efs
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Mi
</code></pre>
<pre><code> kubectl get pvc -n jenkins
NAME               STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
pvc-jenkins-home   Bound    pvc-4ccf3f55-6894-4fee-88d7-58dd7584b837   10Mi       RWO            efs            59m
</code></pre>
<p>Please let me know if any details required from my side</p>

Gowmi
<p>Please remove the <code>subpath</code>from <code>volumeMounts</code> as subPath will overwrite everything under the <code>/var</code> directory. so it should be just like this</p>
<pre><code>volumeMounts:
- mountPath: /var
  name: jenkins-home

</code></pre>
