You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

自定义Jenkins镜像经Helm部署后Pod异常终止问题排查

自定义Jenkins镜像部署后Pod异常终止排查

问题背景

尝试基于jenkins/jenkins:latest自定义镜像以安装Docker,实现Jenkins Pipeline中运行Docker。但部署后jenkins-jenkins Pod以Error状态终止,无有效错误日志,即使未在Dockerfile中安装Docker,仍出现相同问题。

使用的配置文件

Dockerfile(构建为custom_image:latest)

FROM jenkins/jenkins:latest
USER jenkins

values.yaml

jenkins:
  name: 
  image: custom_image:latest

部署命令

helm repo add jenkins https://raw.githubusercontent.com/jenkinsci/kubernetes-operator/master/chart
helm install jenkins jenkins/jenkins-operator -n jenkins -f values.yaml

相关输出信息

kubectl describe pod/jenkins-jenkins 输出

...
Events:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  12s   default-scheduler  Successfully assigned jenkins/jenkins-jenkins to minikube
  Normal  Pulled     11s   kubelet            Container image "docker-jenkins:latest" already present on machine
  Normal  Created    11s   kubelet            Created container jenkins-master
  Normal  Started    11s   kubelet            Started container jenkins-master
  Normal  Pulled     11s   kubelet            Container image "virtuslab/jenkins-operator-backup-pvc:v0.1.0" already present on machine
  Normal  Created    11s   kubelet            Created container backup
  Normal  Started    11s   kubelet            Started container backup
  Normal  Killing    8s    kubelet            Stopping container backup

kubectl logs pod/jenkins-jenkins 输出

...
Defaulted container "jenkins-master" out of: jenkins-master, backup
+ '[' '' == true ']'
+ echo 'To print debug messages set environment variable '\''DEBUG_JENKINS_OPERATOR'\'' to '\''true'\'''
+ mkdir -p /var/lib/jenkins/init.groovy.d
To print debug messages set environment variable 'DEBUG_JENKINS_OPERATOR' to 'true'
+ cp -n /var/jenkins/init-configuration/createOperatorUser.groovy /var/lib/jenkins/init.groovy.d
+ mkdir -p /var/lib/jenkins/scripts
+ cp /var/jenkins/scripts/init.sh /var/jenkins/scripts/install-plugins.sh /var/lib/jenkins/scripts
+ chmod +x /var/lib/jenkins/scripts/init.sh /var/lib/jenkins/scripts/install-plugins.sh
Installing plugins required by Operator - begin
+ echo 'Installing plugins required by Operator - begin'
+ cat
+ [[ -z '' ]]
+ install-plugins.sh
WARN: install-plugins.sh has been removed, please switch to jenkins-plugin-cli

kubectl describe pod/jenkins-jenkins-operator-7c4cd6dc7b-g6m7z 输出

Type     Reason          Age                    From               Message
  ----     ------          ----                   ----               -------
  Normal   Scheduled       18h                    default-scheduler  Successfully assigned jenkins/jenkins-jenkins-operator-7c4cd6dc7b-g6m7z to minikube
  Normal   Pulled          18h                    kubelet            Container image "virtuslab/jenkins-operator:v0.7.1" already present on machine
  Normal   Created         18h                    kubelet            Created container jenkins-operator
  Normal   Started         18h                    kubelet            Started container jenkins-operator
  Normal   SandboxChanged  3m56s                  kubelet            Pod sandbox changed, it will be killed and re-created.
  Warning  BackOff         3m23s                  kubelet            Back-off restarting failed container
  Normal   Pulled          3m11s (x2 over 3m55s)  kubelet            Container image "virtuslab/jenkins-operator:v0.7.1" already present on machine
  Normal   Created         3m11s (x2 over 3m55s)  kubelet            Created container jenkins-operator
  Normal   Started         3m10s (x2 over 3m55s)  kubelet            Started container jenkins-operator

kubectl logs jenkins-jenkins-operator-7c4cd6dc7b-g6m7z 输出

2022-11-22T20:00:50.544Z        DEBUG   controller-jenkins      Jenkins HTTP Service is present {"cr": "jenkins"}
2022-11-22T20:00:50.545Z        DEBUG   controller-jenkins      Jenkins slave Service is present        {"cr": "jenkins"}
2022-11-22T20:00:50.545Z        DEBUG   controller-jenkins      Kubernetes resources are present        {"cr": "jenkins"}
2022-11-22T20:00:50.545Z        DEBUG   controller-jenkins      Jenkins master pod is present   {"cr": "jenkins"}
2022-11-22T20:00:50.545Z        DEBUG   controller-jenkins      Jenkins master pod is terminating       {"cr": "jenkins"}
2022-11-22T20:00:55.546Z        DEBUG   controller-jenkins      Reconciling Jenkins     {"cr": "jenkins"}
2022-11-22T20:00:55.546Z        DEBUG   controller-jenkins      Operator credentials secret is present  {"cr": "jenkins"}
2022-11-22T20:00:55.552Z        DEBUG   controller-jenkins      Scripts config map is present   {"cr": "jenkins"}
2022-11-22T20:00:55.555Z        DEBUG   controller-jenkins      Init configuration config map is present        {"cr": "jenkins"}
2022-11-22T20:00:55.562Z        DEBUG   controller-jenkins      Base configuration config map is present        {"cr": "jenkins"}
2022-11-22T20:00:55.562Z        DEBUG   controller-jenkins      GroovyScripts Secret and ConfigMap added watched labels {"cr": "jenkins"}
2022-11-22T20:00:55.562Z        DEBUG   controller-jenkins      ConfigurationAsCode Secret and ConfigMap added watched labels   {"cr": "jenkins"}
2022-11-22T20:00:55.562Z        DEBUG   controller-jenkins      createServiceAccount with annotations map[]     {"cr": "jenkins"}
2022-11-22T20:00:55.582Z        DEBUG   controller-jenkins      Service account, role and role binding are present      {"cr": "jenkins"}
2022-11-22T20:00:55.582Z        DEBUG   controller-jenkins      Extra role bindings are present {"cr": "jenkins"}
2022-11-22T20:00:55.583Z        DEBUG   controller-jenkins      Jenkins HTTP Service is present {"cr": "jenkins"}
2022-11-22T20:00:55.584Z        DEBUG   controller-jenkins      Jenkins slave Service is present        {"cr": "jenkins"}
2022-11-22T20:00:55.585Z        DEBUG   controller-jenkins      Kubernetes resources are present        {"cr": "jenkins"}
2022-11-22T20:00:55.585Z        DEBUG   controller-jenkins      Jenkins master pod is present   {"cr": "jenkins"}
2022-11-22T20:00:55.585Z        DEBUG   controller-jenkins      Jenkins master pod is terminating       {"cr": "jenkins"}

排查方向建议

  1. 镜像兼容性问题:当前使用的Jenkins Operator版本(v0.7.1)可能与jenkins/jenkins:latest镜像不兼容,建议指定与Operator版本匹配的Jenkins镜像标签,而非使用latest。
  2. 插件安装脚本问题:日志中提示install-plugins.sh已被移除,请切换到jenkins-plugin-cli,Operator的初始化脚本仍在调用废弃的脚本,导致初始化失败。需确认Operator是否支持当前Jenkins镜像的插件安装方式,或修改初始化逻辑使用jenkins-plugin-cli。
  3. 权限问题:自定义镜像中切换到jenkins用户后,可能缺少必要的目录权限或环境变量,导致初始化脚本无法正常执行。可尝试在Dockerfile中添加权限配置,或先以root用户完成初始化后再切换回jenkins。
  4. Pod终止原因:查看Pod的退出码(kubectl get pod jenkins-jenkins -o jsonpath='{.status.containerStatuses[*].state.terminated.exitCode}'),确定具体终止原因;同时检查backup容器的日志(kubectl logs jenkins-jenkins -c backup),确认是否是backup容器异常导致Pod终止。

内容的提问来源于stack exchange,提问作者somerandomdrunkcoder

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 08:45:32