ReplicaSet因无效而失败:spec.template.metadata.labels [英] ReplicaSet fails with invalid: spec.template.metadata.labels
问题描述
出于我的学习目的,我正在尝试对plicateSet进行一些研究.我能够使用matchLabels成功创建一个copysetSet.为了测试matchExpression选择器,我首先创建了一个Pod,然后创建了一个新的副本集,以测试该副本集是否能够检查正在运行的Pod中的标签.但这失败并显示错误.这是我到目前为止所做的.
I am trying to do some research on replicaSet for my learning purpose. I was able to create a replicaSet successfully with matchLabels. To test the matchExpression selector, I created a pod first then a new replica set to test if the replica set will be able to check the labels from the running pods. But this failed with error. Here is what I did so far.
- 首先使用特定标签创建了一个广告连播. Pod成功运行.
- 使用matchExpressions创建一个副本集,将matchExpressions的值与Pod中指定的标签相匹配.
第二步之后,我得到了错误.以下是YAML文件和错误. 您能帮我理解这里的问题吗?
After the second step I get error. Below are the YAML files and the error. Can you help me understand the issue here ?
这是pod-definition.yaml
Here is the pod-definition.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx-app
labels:
tier: frontend1
spec:
containers:
- name: nginx-c
image: nginx
这是副本集-definition.yaml
Here is the replicaset-definition.yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: replicaset-2
spec:
replicas: 2
selector:
matchExpressions:
- {key: tier, operator: In, values: [frontend1]}
template:
metadata:
labels:
tier: nginx
spec:
containers:
- name: nginx
image: nginx
创建副本集时出错:
master $ kubectl create -f/root/replicaset-definition.yaml
master $ kubectl create -f /root/replicaset-definition.yaml
ReplicaSet"replicaset-2"无效:
spec.template.metadata.labels:无效值:
map [string] string {"tier":"nginx"}:selector
与模板不匹配
labels
The ReplicaSet "replicaset-2" is invalid:
spec.template.metadata.labels: Invalid value:
map[string]string{"tier":"nginx"}: selector
does not match template
labels
推荐答案
能否通过更改模板部分中的标签来尝试以下操作?
Can you try with the following by changing the label in template section.
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: replicaset-2
spec:
replicas: 2
selector:
matchExpressions:
- {key: tier, operator: In, values: [frontend1]}
template:
metadata:
labels:
tier: frontend1
spec:
containers:
- name: nginx
image: nginx
这篇关于ReplicaSet因无效而失败:spec.template.metadata.labels的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!