问题描述
我使用 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 文件中缺少几个必需的密钥。
-
apiVersion
键 - Pod 的 api 版本当前为v1
-
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 凭证。