【问题标题】:ReplicaSet throwing error "selector does not match template labels" [duplicate]ReplicaSet 抛出错误“选择器与模板标签不匹配”[重复]
【发布时间】:2020-07-27 16:13:43
【问题描述】:

在创建 ReplicaSet 时,我收到以下错误:

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

下面是我的yaml文件replicaset.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

我错过了什么?我试过ReplicationController 使用相同的 yaml(没有选择器并使用 v1 版本),它工作正常。

【问题讨论】:

    标签: kubernetes


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 2019-04-17
      • 2020-03-28
      • 2021-09-15
      • 2020-11-20
      • 2018-03-14
      • 1970-01-01
      • 1970-01-01
      • 2022-08-21
      • 1970-01-01
      相关资源
      最近更新 更多