![](/img/trans.png)
[英]kubernetes: can't deploy jenkins images with persistent volume with RW access
[英]Persistent Volume for Jenkins on Kubernetes
我正在嘗試在本地 Kubernetes 集群上部署 Jenkins 映像。 部署成功,但我無法使持久性數據正常工作。 沒有拋出任何錯誤並且新的 pod 成功啟動,唯一的問題是它不是持久的。
Jenkins Dockerfile:
FROM jenkins/jenkins:lts
ENV JENKINS_USER admin
ENV JENKINS_PASS admin
# Skip initial setup
ENV JAVA_OPTS -Djenkins.install.runSetupWizard=false
COPY plugins.txt /usr/share/jenkins/plugins.txt
RUN /usr/local/bin/install-plugins.sh < /usr/share/jenkins/plugins.txt
USER root
RUN apt-get update \
&& apt-get install -qqy apt-transport-https ca-certificates curl gnupg2 software-properties-common
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
RUN add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/debian \
$(lsb_release -cs) \
stable"
RUN apt-get update -qq \
&& apt-get install docker-ce -y
RUN usermod -aG docker jenkins
RUN apt-get clean
RUN curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose
USER jenkins
Kubernetes 部署文件:
apiVersion: apps/v1
kind: Deployment
metadata:
name: jenkins
spec:
replicas: 1
selector:
matchLabels:
app: jenkins
template:
metadata:
labels:
app: jenkins
spec:
containers:
- name: jenkins
image: mikemanders/my-jenkins-image:1.1
env:
- name: JAVA_OPTS
value: -Djenkins.install.runSetupWizard=false
ports:
- name: http-port
containerPort: 8080
- name: jnlp-port
containerPort: 50000
volumeMounts:
- name: jenkins-home
mountPath: /var/lib/jenkins
subPath: jenkins
volumes:
- name: jenkins-home
persistentVolumeClaim:
claimName: jenkins-pv-claim
Kubernetes 持久卷:
apiVersion: v1
kind: PersistentVolume
metadata:
name: jenkins-pv
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 6Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/var/lib"
持久卷聲明
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: jenkins-pv-claim
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
我正在使用 Minikube 進行本地開發。 當然還有 Kubectl。
不要看到我做錯了什么。 感謝所有幫助。
常規 dockerhub jenkins 映像使用路徑/var/jenkins_home
,而不是/var/lib/jenkins
用於持久數據。 因此,您應該使用該路徑來安裝您的持久卷。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.