Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Volume mounting in Jenkins on Kubernetes

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.

Here's my deployment.yml file. The image is based off jenkins/jenkins

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: {}

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)

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

Am I misunderstanding how this volume mount is meant to work?


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.

like image 547
djt Avatar asked Oct 17 '22 00:10

djt


1 Answers

You should use PersistentVolumes along with StatefulSet instead of Deployment resource if you wish your data to survive re-deployments|restarts of your pod.

like image 111
kofucii Avatar answered Nov 15 '22 06:11

kofucii