title: Volume mounting in Jenkins on Kubernetes
body: <p>I'm trying to setup Jenkins to run in a container on Kubernetes, but I'm having trouble persisting the volume for the Jenkins home directory.</p>
  
  <p>Here's my deployment.yml file.  The image is based off <code>jenkins/jenkins</code></p>
  
  <pre><code>apiVersion: extensions/v1beta1
  kind: Deployment
  metadata:
    name: jenkins-deployment
    labels:
      app: jenkins
  spec:
    replicas: 1
    selector:
      matchLabels:
        app: jenkins
    template:
      metadata:
        labels:
          app: jenkins
      spec:
        containers:
        - name: jenkins
          image: 1234567.dkr.ecr.us-east-1.amazonaws.com/mycompany/jenkins
          imagePullPolicy: "Always"
          ports:
          - containerPort: 8080
          volumeMounts:
            - name: jenkins-home
              mountPath: /var/jenkins_home
        volumes:
          - name: jenkins-home
            emptyDir: {}
  </code></pre>
  
  <p>However, if i then push a new container to my image repository and update the pods using the below commands, Jenkins comes back online but asks me to start from scratch (enter admin password, none of my Jenkins jobs are there, no plugins etc)</p>
  
  <pre><code>kubectl apply -f kubernetes (where my manifests are stored)
  
  kubectl set image deployment/jenkins-deployment jenkins=1234567.dkr.ecr.us-east-1.amazonaws.com/mycompany/jenkins:$VERSION
  </code></pre>
  
  <p>Am I misunderstanding how this volume mount is meant to work?</p>
  
  <hr>
  
  <p>As an aside, I also have backup and restore scripts which backup the Jenkins home directory to s3, and download it again, but that's somewhat outside the scope of this issue.</p>