user51
user51

Reputation: 10143

Kubernetes: Unable to create replicaSet: error: no objects passed to create

I'm trying to create replicaSet in kubernetes by using below yaml file.

            apiVersion: apps/v1
            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 run the below command

$ kubectl create -f replicaSet/kubia-replicaset.yaml

This command gave me the below error

error: no objects passed to create

Any idea why I'm getting this error. How to resolve this error and successfully create the replicaSet?

Upvotes: 1

Views: 14401

Answers (3)

Naima
Naima

Reputation: 1

You have made template a child of selector while it should be its sibling. so the correct format will be:

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

Upvotes: 0

Patrick W
Patrick W

Reputation: 4899

error: unable to recognize "kubia-replicaset.yaml": no matches for apps/, Kind=ReplicaSet

Means that GKE does not recognize ReplicaSet within apiVersion: apps/v1 I checked my cluster (I normally use deployments), pulled my replicaSet and it shows up as:

apiVersion: extensions/v1beta1
kind: ReplicaSet

The apiVersion will depend on the Kubernetes version you are using with your cluster. app/v1 is for 1.9.0 and up, anything earlier still uses v1beta1.

Upvotes: 0

Nitish Kumar
Nitish Kumar

Reputation: 4870

This image should be parallel to name

containers: 
    - name: kubia
      image: luksa/kubia

Upvotes: 2

Related Questions