我正在K8S集群中设置Jenkins机器,并希望为我的Kubernetes集群预先配置云属性。
基于这个原因,我想在启动时加载自定义的config.xml
文件。
我的config.xml
当前位于名为jenkins-config
的configMap中,并且包含带有我的编辑的整个XML文件。
现在有了我正在使用的Jenkins映像,它将加载/var/jenkins_home/
下的所有配置
这意味着config.xml
文件在/var/jenkins_home
下。
/var/jenkins_home
当然是持久的。
我将configMap引入为VolumeMount。
我的deployment.yaml文件是:
spec:
replicas: 1
template:
metadata:
labels:
app: jenkins
release: 1.1.1
spec:
containers:
- name: jenkins
image: jenkins-master:1.0
env:
- name: JAVA_OPTS
value: -Djenkins.install.runSetupWizard=false
ports:
- name: http-port
containerPort: 8080
- name: jnlp-port
containerPort: 54000
volumeMounts:
- name: jenkins-home
mountPath: /var/jenkins_home
readOnly: false
- name: jenkins-config
mountPath: /var/jenkins_home/config.xml
subPath: config.xml
volumes:
- name: jenkins-home
emptyDir: {}
- name: jenkins-config
configMap:
name: jenkins-config
现在,我可以访问我的Pod并验证新配置确实存在,但是我的Jenkins给出了以下错误:
WARNING: Unable to move atomically, falling back to non-atomic move.
java.nio.file.FileSystemException: /var/jenkins_home/atomic1870316694682040724tmp -> /var/jenkins_home/config.xml: Device or resource busy
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:91)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
at sun.nio.fs.UnixCopyFile.move(UnixCopyFile.java:396)
at sun.nio.fs.UnixFileSystemProvider.move(UnixFileSystemProvider.java:262)
at java.nio.file.Files.move(Files.java:1395)
at hudson.util.AtomicFileWriter.commit(AtomicFileWriter.java:191)
at hudson.XmlFile.write(XmlFile.java:198)
at jenkins.model.Jenkins.save(Jenkins.java:3221)
at jenkins.model.Jenkins.saveQuietly(Jenkins.java:3227)
at jenkins.model.Jenkins.setSecurityRealm(Jenkins.java:2505)
at jenkins.model.Jenkins$16.run(Jenkins.java:3188)
at org.jvnet.hudson.reactor.TaskGraphBuilder$TaskImpl.run(TaskGraphBuilder.java:169)
at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:296)
at jenkins.model.Jenkins$5.runTask(Jenkins.java:1066)
at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:214)
at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:117)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Sep 15, 2018 10:06:23 PM hudson.util.AtomicFileWriter commit
INFO: The target file /var/jenkins_home/config.xml was already existing
Sep 15, 2018 10:06:23 PM hudson.util.AtomicFileWriter commit
WARNING: Unable to move /var/jenkins_home/atomic1870316694682040724tmp to /var/jenkins_home/config.xml. Attempting to delete /var/jenkins_home/atomic1870316694682040724tmp and abandoning.
Sep 15, 2018 10:06:23 PM jenkins.model.Jenkins saveQuietly
WARNING: null
java.nio.file.FileSystemException: /var/jenkins_home/config.xml: Device or resource busy
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:91)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
at sun.nio.fs.UnixCopyFile.move(UnixCopyFile.java:447)
at sun.nio.fs.UnixFileSystemProvider.move(UnixFileSystemProvider.java:262)
at java.nio.file.Files.move(Files.java:1395)
at hudson.util.AtomicFileWriter.commit(AtomicFileWriter.java:206)
at hudson.XmlFile.write(XmlFile.java:198)
at jenkins.model.Jenkins.save(Jenkins.java:3221)
at jenkins.model.Jenkins.saveQuietly(Jenkins.java:3227)
at jenkins.model.Jenkins.setSecurityRealm(Jenkins.java:2505)
at jenkins.model.Jenkins$16.run(Jenkins.java:3188)
at org.jvnet.hudson.reactor.TaskGraphBuilder$TaskImpl.run(TaskGraphBuilder.java:169)
at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:296)
at jenkins.model.Jenkins$5.runTask(Jenkins.java:1066)
at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:214)
at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:117)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Suppressed: java.nio.file.FileSystemException: /var/jenkins_home/atomic1870316694682040724tmp -> /var/jenkins_home/config.xml: Device or resource busy
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:91)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
at sun.nio.fs.UnixCopyFile.move(UnixCopyFile.java:396)
at sun.nio.fs.UnixFileSystemProvider.move(UnixFileSystemProvider.java:262)
at java.nio.file.Files.move(Files.java:1395)
at hudson.util.AtomicFileWriter.commit(AtomicFileWriter.java:191)
... 13 more
看起来像詹金斯(Jenkins)加载了默认的config.xml
文件,然后用我发送的文件覆盖了该文件,这使詹金斯(Jenkins)非常惊讶。
我可以将这部分设置为我想使用K8S覆盖的Docker Image BUT,而不是在Image中创建文件。
关于如何在Jenkins启动时安全地引入config.xml
文件的任何想法?
编辑
另一种尝试::
我什至尝试了以下配置:
volumeMounts:
- name: jenkins-home
mountPath: /var/jenkins_home
readOnly: false
volumes:
- name: jenkins-home
configMap:
name: jenkins-config
items:
- key: config.xml
path: config.xml
但是会产生:
kubectl logs -n jenkins-pipeline jenkins-bc879c4df-m8nlc
touch: cannot touch '/var/jenkins_home/copy_reference_file.log': Read-only file system
Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?
答案 0 :(得分:0)
您基本上是将/var/jenkins_home/config.xml
安装在/var/jenkins_home
之上,而jenkins无法对其进行写入。试试这个:
spec:
replicas: 1
template:
metadata:
labels:
app: jenkins
release: 1.1.1
spec:
containers:
- name: jenkins
image: jenkins-master:1.0
env:
- name: JAVA_OPTS
value: -Djenkins.install.runSetupWizard=false
ports:
- name: http-port
containerPort: 8080
- name: jnlp-port
containerPort: 54000
volumeMounts:
- name: jenkins-home
mountPath: /etc/config
volumes:
- name: jenkins-home
hostPath:
# directory location on host
path: /data
# this field is optional
type: Directory
configMap:
name: jenkins-config
items:
- key: config
path: config.xml