创建副本集时出错 - io.k8s.api.apps.v1.ReplicaSet 中未知的未知字段“replicas”

2 replicaset kubernetes kubernetes-pod

团队,我正在尝试创建一个副本集,但出现错误:

验证数据时出错:

[ValidationError(ReplicaSet):io.k8s.api.apps.v1.ReplicaSet 中未知字段“replicas”,ValidationError(ReplicaSet):io.k8s.api.apps.v1.ReplicaSet 中未知字段“selector”,ValidationError(ReplicaSet) .spec): io.k8s.api.apps.v1.ReplicaSetSpec 中缺少必填字段“选择器”];如果您选择忽略这些错误,请使用 --validate=false 关闭验证

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: test-pod-10sec-via-rc1
  labels:
    app: pod-label
spec:
  template:
  metadata:
  name: test-pod-10sec-via-rc1
  labels:
      app: feature-pod-label
  namespace: test-space
spec:
  containers:
  - name: main
    image: ubuntu:latest
    command: ["bash"]
    args: ["-xc", "sleep 10"]
    volumeMounts:
    - name: in-0
      mountPath: /in/0
      readOnly: true
  volumes:
  - name: in-0
    persistentVolumeClaim:
      claimName: 123-123-123
      readOnly: true
  nodeSelector:
    kubernetes.io/hostname: node1
replicas: 1
selector:
  matchLabels:
    app: feature-pod-label
Run Code Online (Sandbox Code Playgroud)

Pra*_*dha 5

您的 yaml 文件中存在缩进问题,正确的 yaml 将是:

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: test-pod-10sec-via-rc1
  labels:
    app: pod-label
spec:
  template:
  metadata:
  name: test-pod-10sec-via-rc1
  labels:
      app: feature-pod-label
  namespace: test-space
spec:
  template:
    spec:
      containers:
      - name: main
        image: ubuntu:latest
        command: ["bash"]
        args: ["-xc", "sleep 10"]
        volumeMounts:
        - name: in-0
          mountPath: /in/0
          readOnly: true
      volumes:
      - name: in-0
        persistentVolumeClaim:
          claimName: 123-123-123
          readOnly: true
      nodeSelector:
       kubernetes.io/hostname: node1
  replicas: 1
  selector:
    matchLabels:
      app: feature-pod-label
Run Code Online (Sandbox Code Playgroud)