微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在Jenkins中使用Pod yaml文件来创建容器

如何解决如何在Jenkins中使用Pod yaml文件来创建容器

我使用 POD yaml 文件在 Kubernetes 中创建了一个 Pod。

我的 yaml 文件很简单,如下所示:

kind: Pod
spec:
  containers:
  - name: kaniko
    image: gcr.io/kaniko-project/executor:debug
    imagePullPolicy: Always
    command:
    - /busyBox/cat
    tty: true

但我收到此错误消息:

nodes are available: 33 node(s) didn't match node selector.

我在 Jenkins 管道中运行这个 pod 文件,以便可以安装 Kaniko 来构建 docker 镜像。

有什么解决办法吗?

解决方法

您的 YAML 文件中缺少几个必需的密钥。

  1. apiVersion 键 - Pod 的 api 版本当前为 v1
  2. metadata 键 - 有助于唯一标识对象的数据,包括 name 字符串、UID 和可选的 namespace

您可以阅读有关在 Kubernetes docs 中创建静态 Pod 的更多信息,如果您想要一些关于 kaniko Pod 的示例,可以使用 here

因此,最小正确的 pod YAML 应该如下所示:

kind: Pod
apiVersion: v1
metadata:
  # specify your pod name
  name: <pod-name>
spec:
  containers:
  - name: kaniko
    image: gcr.io/kaniko-project/executor:debug
    imagePullPolicy: Always
    command:
    - /busybox/cat
    tty: true

解决问题: 您可以使用 nodeSelector 键指定哪个 Pod 应该在哪个节点上运行。您需要在 spec 下指定它。例如:

spec:
  containers:
  - name: kaniko
    image: gcr.io/kaniko-project/executor:debug
    imagePullPolicy: Always
    command:
    - /busybox/cat
    tty: true
  #here it is
  nodeSelector:
    # and here is node label
    <label-name>: <label-value>

您可以使用

找到您的节点标签
kubectl describe node <node-name>

或使用

为其添加标签
kubectl label node <node-name> <label-name>=<label-value>

您可以在 docs 中找到更多相关信息。

,

你可以试试这个作为例子:

pipeline {
  agent {
    kubernetes {
      yaml """
apiVersion: v1
kind: Pod
metadata:
  labels:
    jenkins: worker
spec:
  containers:
  - name: kaniko
    image: gcr.io/kaniko-project/executor:debug
    command: ["/busybox/cat"]
    tty: true
    volumeMounts:
      - name: dockercred
        mountPath: /root/.docker/
  volumes:
  - name: dockercred
    secret:
      secretName: dockercred
"""
    }
  }
  stages {
    stage('Stage 1: Build with Kaniko') {
      steps {
        container('kaniko') {
          sh '/kaniko/executor --context=git://github.com/repository/project.git \
                  --destination=repository/image:tag \
                  --insecure \
                  --skip-tls-verify  \
                  -v=debug'
        }
      }
    }  
  }
}

我挂载的 secret 是 Kaniko 使用的 docker 凭证。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?