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

如何在jenkinsci/kubernetes-plugin用YAML定义Pod?使用该功能时出现故障

Hey there! Let's troubleshoot this issue you're facing with the Jenkins Kubernetes plugin when switching to YAML-defined slave pods. Since you mentioned modifying your pipeline from the podTemplate container syntax to YAML, here are the most common pitfalls and fixes to resolve your exception:

1. Fix YAML Syntax Mistakes

YAML is super strict about indentation, spacing after colons, and structure—even a tiny mistake can break the pod definition. Let's compare your original code snippet to a properly formatted YAML version:

Original pipeline snippet (containerTemplate style):

def label = "kubernetes" 
podTemplate(label: label, containers: [
    containerTemplate(name: 'jnlp', image: 'artifactory.baorg.com:5001/sum/coreimage:1', ttyEnabled: true)
]) {
    // Your pipeline steps here
}

Converted YAML-based podTemplate (correct format):

def label = "kubernetes"
podTemplate(label: label, yaml: '''
  apiVersion: v1
  kind: Pod
  metadata:
    labels:
      jenkins: slave
  spec:
    containers:
    - name: jnlp
      image: artifactory.baorg.com:5001/sum/coreimage:1
      tty: true
      stdin: true  # Critical for JNLP agent to maintain connection
''') {
    // Your pipeline steps here
}

Key notes:

  • Ensure consistent 2-space indentation (tabs can cause errors)
  • Add stdin: true alongside tty: true—the JNLP agent needs this to stay connected
  • Avoid trailing spaces in YAML lines

2. Verify JNLP Container Requirements

Your custom coreimage must have Java installed (the JNLP agent needs it to communicate with Jenkins). If the image lacks Java, you'll get a "command not found" error when the pod starts. To fix this:

  • Either use a base image with pre-installed Java, or
  • Add an init container to install Java, or
  • Update your coreimage Dockerfile to include Java

3. Resolve Image Pull or Permission Issues

If the exception mentions "image pull failed" or permission errors:

  • Confirm your Kubernetes nodes can reach artifactory.baorg.com:5001 (check network policies, firewalls)
  • Add an image pull secret to the pod YAML if your Artifactory repo requires authentication:
    spec:
      imagePullSecrets:
      - name: artifactory-pull-secret  # Replace with your secret name
      containers:
      - name: jnlp
        # ... rest of container config
    
  • Ensure the Jenkins service account has permissions to create pods and pull images in your cluster

4. Avoid Parameter Conflicts

When using the yaml parameter in podTemplate, do NOT mix it with other pod configuration parameters like containers, volumes, or envVars. These will conflict with the YAML definition and cause unexpected errors. Stick to only label and yaml in the podTemplate call when using custom YAML.

If you can share the exact error message from the Jenkins console or Kubernetes pod events, we can narrow this down even further!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.22 07:34:15