Jenkins in k8s don`t save install plugin

12/13/2020

There is the following job, save jenkins state using pv / pvc. The problem is that it can't mount in /var/jenkins_home ,but it is mounted in any other folder, tell me what to do) Or save the state of jenkins plugins to a folder and then get them from there using some script?

jenkins-deployment.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: jenkins-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: jenkins
  template:
    metadata:
      labels:
        app: jenkins
    spec:
      containers:
      - name: jenkins
        image: jenkins/jenkins:lts
        ports:
          - name: http-port
            containerPort: 8080
        volumeMounts:
          - name: test-pvc
            mountPath: /var/jenkins_home/
      volumes:
        - name: test-pvc
          persistentVolumeClaim:
            claimName: test-pvc

pv.yml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: jenkins-pv
spec:
  capacity:
    storage: 2Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteMany
  storageClassName: local-storage
  hostPath:
    path: /data/jenkins_home/

pvc.yml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: test-pvc
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 2Gi
  volumeName: jenkins-pv
  storageClassName: local-storage
-- Benny and the Jets
devops
jenkins
kubernetes

1 Answer

12/13/2020

I figured it out))

apiVersion: apps/v1
kind: Deployment
metadata:
  name: jenkins-deployment
  namespace: jenkins
spec:
  replicas: 1
  selector:
    matchLabels:
      app: jenkins
  template:
    metadata:
      labels:
        app: jenkins
    spec:
      containers:
      - name: jenkins
        image: jenkins/jenkins:lts
        ports:
          - name: http-port
            containerPort: 8080
        volumeMounts:
          - name: jenkins-storage
            mountPath: /var/jenkins_home/
      volumes:
        - name: jenkins-storage
          persistentVolumeClaim:
            claimName: jenkins-pv-clain
---
apiVersion: v1
kind: Service
metadata:
  name: jenkins
  namespace: jenkins
spec:
  type: NodePort
  ports:
    - port: 8080
      targetPort: 8080
      nodePort: 30000
  selector:
    app: jenkins

---

  apiVersion: v1
  kind: PersistentVolumeClaim
  metadata:
    name: jenkins-pv-clain
    namespace: jenkins
  spec:
    accessModes:
    - ReadWriteOnce
    resources:
      requests:
        storage: 1Gi
-- Benny and the Jets
Source: StackOverflow