'kubernetes: ReplicaSet error: error validating data: unknown objec t type schema.GroupVersionKind

I have below yaml file for creating ReplicaSet.

apiVersion: apps/v1beta1
kind: ReplicaSet
metadata:
    name: kubia
spec:
    replicas: 2
    selector:
        matchLabels:
            app: kubia
        template:
            metadata:
                labels:
                    app: kubia
            spec:
                containers: 
                - name: kubia
                image: luksa/kubia

Then I tried to create ReplicaSet using the below command and I get error.

$ kubectl create -f chapter4/kubia-replicaset.yaml
error: error validating "chapter4/kubia-replicaset.yaml": error validating data: unknown objec
t type schema.GroupVersionKind{Group:"apps", Version:"v1beta1", Kind:"ReplicaSet"}; if you choose to ignore these errors, turn validation off with --validate=false

I've tried different values of apiVersion like apps/v1, apps/v1beta1, extensions/v1, extensions/v1beta1 etc but nothing helped.

My kubernetes version is -

$ kubectl versionClient Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.6", GitCommit:"6260bb08c46c31eea6cb538b34a9ceb3e406689c", GitTreeState:"clean", BuildDate:"2017-12-21T06:34:11Z", GoVers
ion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}Server Version: version.Info{Major:"1", Minor:"8+", GitVersion:"v1.8.7-gke.1", GitCommit:"192ccad06d24af9828cbf42330e1d915cb586406", GitTreeState:"clean", BuildDate:"2018-01-31T21:39:04Z",
GoVersion:"go1.8.3b4", Compiler:"gc", Platform:"linux/amd64"}

Any idea what should be the correct value apiVersion.



Solution 1:[1]

According to the Kubernetes 1.8 API reference, the ReplicaSet resource is available in the following API groups:

  • apps/v1beta2
  • extensions/v1beta1 (deprecated)

Starting at Kubernetes 1.9, the ReplicaSet resource can additionally be found in the apps/v1 API group, deprecating the previous apps/v1beta2 object.

Solution 2:[2]

edit apps/v1beta2 to apps/v1

then

kubectl create -f kubia-replicaset.yaml

replicaset.apps/kubia created

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 helmbert
Solution 2 BiaowuDuan