Kubernetes Deployment file error: Found invalid field selector for v1.PodSpec
Kubernetes Deployment file error: Found invalid field selector for v1.PodSpec
当我尝试使用 YAML 文件创建我的部署时,我遇到了一个无效的字段选择器错误。错误是error validating data: found invalid field selector for v1.PodSpec
,我的文件可以在下面看到。
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: zalenium-deployment
spec:
replicas: 1
template:
metadata:
labels:
app: zalenium
spec:
serviceAccountName: zalenium
serviceAccount: zalenium
selector:
app: zalenium
role: grid
containers:
- name: zalenium-pod
image: dosel/zalenium
ports:
- containerPort: 4444
protocol: TCP
volumeMounts:
- name: zalenium-shared
mountPath: /tmp/mounted
- name: zalenium-videos
mountPath: /home/seluser/videos
resources:
requests:
memory: "250m"
cpu: "500m"
limits:
memory: "1Gi"
volumes:
- name: zalenium-shared
persistentVolumeClaim:
claimName: zalenium-shared-claim
- name: zalenium-videos
persistentVolumeClaim:
claimName: zalenium-videos-claim
我试过使用在线 YAML 文件验证器,它们似乎没有显示格式有任何问题。当我尝试使用 validate=false 标志创建上面的部署时,部署运行,但随后 pods 不断崩溃并重新启动 (crashLoopBackOff)。我应该调查什么?我仍然对 k8s 很熟悉,但从错误来看,我认为它与我部署中的容器规范有关。关于接近这个的任何提示?谢谢!
由于错误消息指出选择器是 v1.PodSpec
的 invalid field
- 因此此字段在 .spec.template.spec.selector
处无效。我想你要找的是 .spec.selector。
话虽如此,文档指出:
If specified, .spec.selector must match
.spec.template.metadata.labels, or it will be rejected by the API.
因此您还必须将 role: grid
添加到您的元数据标签(在 .spec.template.metadata.labels
处)。你的 .yaml 文件看起来像这样:
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: zalenium-deployment
spec:
selector:
matchLabels:
app: zalenium
role: grid
replicas: 1
template:
metadata:
labels:
app: zalenium
role: grid
spec:
serviceAccountName: zalenium
serviceAccount: zalenium
containers:
- name: zalenium-pod
image: dosel/zalenium
ports:
- containerPort: 4444
protocol: TCP
volumeMounts:
- name: zalenium-shared
mountPath: /tmp/mounted
- name: zalenium-videos
mountPath: /home/seluser/videos
resources:
requests:
memory: "250m"
cpu: "500m"
limits:
memory: "1Gi"
volumes:
- name: zalenium-shared
persistentVolumeClaim:
claimName: zalenium-shared-claim
- name: zalenium-videos
persistentVolumeClaim:
claimName: zalenium-videos-claim
当我尝试使用 YAML 文件创建我的部署时,我遇到了一个无效的字段选择器错误。错误是error validating data: found invalid field selector for v1.PodSpec
,我的文件可以在下面看到。
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: zalenium-deployment
spec:
replicas: 1
template:
metadata:
labels:
app: zalenium
spec:
serviceAccountName: zalenium
serviceAccount: zalenium
selector:
app: zalenium
role: grid
containers:
- name: zalenium-pod
image: dosel/zalenium
ports:
- containerPort: 4444
protocol: TCP
volumeMounts:
- name: zalenium-shared
mountPath: /tmp/mounted
- name: zalenium-videos
mountPath: /home/seluser/videos
resources:
requests:
memory: "250m"
cpu: "500m"
limits:
memory: "1Gi"
volumes:
- name: zalenium-shared
persistentVolumeClaim:
claimName: zalenium-shared-claim
- name: zalenium-videos
persistentVolumeClaim:
claimName: zalenium-videos-claim
我试过使用在线 YAML 文件验证器,它们似乎没有显示格式有任何问题。当我尝试使用 validate=false 标志创建上面的部署时,部署运行,但随后 pods 不断崩溃并重新启动 (crashLoopBackOff)。我应该调查什么?我仍然对 k8s 很熟悉,但从错误来看,我认为它与我部署中的容器规范有关。关于接近这个的任何提示?谢谢!
由于错误消息指出选择器是 v1.PodSpec
的 invalid field
- 因此此字段在 .spec.template.spec.selector
处无效。我想你要找的是 .spec.selector。
话虽如此,文档指出:
If specified, .spec.selector must match .spec.template.metadata.labels, or it will be rejected by the API.
因此您还必须将 role: grid
添加到您的元数据标签(在 .spec.template.metadata.labels
处)。你的 .yaml 文件看起来像这样:
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: zalenium-deployment
spec:
selector:
matchLabels:
app: zalenium
role: grid
replicas: 1
template:
metadata:
labels:
app: zalenium
role: grid
spec:
serviceAccountName: zalenium
serviceAccount: zalenium
containers:
- name: zalenium-pod
image: dosel/zalenium
ports:
- containerPort: 4444
protocol: TCP
volumeMounts:
- name: zalenium-shared
mountPath: /tmp/mounted
- name: zalenium-videos
mountPath: /home/seluser/videos
resources:
requests:
memory: "250m"
cpu: "500m"
limits:
memory: "1Gi"
volumes:
- name: zalenium-shared
persistentVolumeClaim:
claimName: zalenium-shared-claim
- name: zalenium-videos
persistentVolumeClaim:
claimName: zalenium-videos-claim