Error creating replicaset - unknown unknown field "replicas" in io.k8s.api.apps.v1.ReplicaSet

1/9/2019

Team, I am trying to create a replica set but getting error as

error validating data:

[ValidationError(ReplicaSet): unknown field "replicas" in io.k8s.api.apps.v1.ReplicaSet, ValidationError(ReplicaSet): unknown field "selector" in io.k8s.api.apps.v1.ReplicaSet, ValidationError(ReplicaSet.spec): missing required field "selector" in io.k8s.api.apps.v1.ReplicaSetSpec]; if you choose to ignore these errors, turn validation off with --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
-- fma abd
kubernetes
kubernetes-pod
replicaset

1 Answer

1/10/2019

You have indentation issue in your yaml file, the correct yaml will be:

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
-- Prafull Ladha
Source: StackOverflow