Jenkins POD重启如何持久化Jenkins配置和插件
Posted
技术标签:
【中文标题】Jenkins POD重启如何持久化Jenkins配置和插件【英文标题】:Jenkins POD restarts how to persists Jenkins configuration and plugin 【发布时间】:2021-08-04 07:57:37 【问题描述】:我已将我的 Jenkins 部署为 kubernetes yaml 文件的一部分,并且还启用了 Persist 卷声明,当我的 Jenkins pod 重新启动时,我失去了所有工作和配置,这意味着我需要重新安装所有 Jenkins 建议插件,配置Kubernetes 云,配置 git repo,并创建新的管道作业。
云请帮我如何避免上述情况。
vi jenkins-deployment.yaml
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: "/var"
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
vi jenkins-pvc.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: pvc-jenkins-home
namespace: jenkins
spec:
storageClassName: efs
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Mi
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
如果我需要任何详细信息,请告诉我
【问题讨论】:
【参考方案1】:请从volumeMounts
中删除subpath
,因为子路径将覆盖/var
目录下的所有内容。所以应该是这样的
volumeMounts:
- mountPath: /var
name: jenkins-home
【讨论】:
以上是关于Jenkins POD重启如何持久化Jenkins配置和插件的主要内容,如果未能解决你的问题,请参考以下文章
配置Jenkins连接kubernetes的Pod Template模板
Jenkins-Kubernetes插件实现使用Pod作为 Agent-超详细