docker - Kubernetes 上 Jenkins 的持久卷
问题描述
我正在尝试在本地 Kubernetes 集群上部署 Jenkins 映像。部署成功,但我无法使持久性数据正常工作。没有抛出任何错误并且新的 pod 成功启动,唯一的问题是它不是持久的。
詹金斯 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
用于持久数据。因此,您应该使用该路径来安装您的持久卷。
推荐阅读
- excel - 如何匹配逗号分隔的列表然后使用索引在excel中获取逗号分隔的结果
- ruby-on-rails - 在 Rails/RSpec 中存根 Dry::Matcher 案例
- google-api - 发送具有不同描述的 Google 日历活动
- visual-studio - 如何创建时间戳 url 或在哪里可以找到 MSIX 应用程序包的免费时间戳 url
- django - “布尔”对象没有“保存”属性
- azure-devops - Azure DevOps API 获取先前发布任务的状态
- go - Golang:可以处理 2 个不同结构的 Unmarshal 函数
- sql-server -
SQL 服务器 - java - 默认情况下,Java 8 在容器中运行时是否总是消耗至少 1GB 的 RAM?
- python - 字符串到字典中的参数