ReplicaSet引发错误“选择器与模板标签不匹配”

时间:2020-07-26 15:40:04

标签: kubernetes

在创建ReplicaSet时,出现以下错误:

ReplicaSet“ julrs”无效:spec.template.metadata.labels: 无效的值:map [string] string {“ type”:“ july-26”}:selector确实 与模板labels

不匹配

下面是我的yaml文件copysetset.yml文件

apiVersion: apps/v1
kind: ReplicaSet
metadata:
    name: julrs
    labels:
        type: jul-26
spec:
    template:
       metadata:
           labels:
               type: july-26
       spec:
           containers:
               - name: jul-c1
                 image: nginx
    replicas: 2
    selector:
        matchLabels:
            type: jul-26

我想念什么?我曾尝试使用相同的Yaml(没有选择器并使用v1版本)来ReplicationController,但工作正常。

1 个答案:

答案 0 :(得分:1)

嗯,yaml文件应该是这样的

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: julrs
  labels:
    type: july-26
spec:
  replicas: 2
  selector:
    matchLabels:
      type: july-26 <-----This 
  template:
    metadata:
      labels:
        type: july-26 <-------this should be same as above
    spec:
      containers:
      - name: jul-c1
        image: nginx