<p>I want to create a ReplicaSet with separate pods.</p>
<h3><code>Pods</code></h3>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Pod
metadata:
  name: user-pod
  labels:
    app: user-pod
spec:
  containers:
    - name: user-container
      image: kia9372/store-user
</code></pre>
<h3><code>Replicaset</code></h3>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: user-replicaset
  labels:
    app: user-replicaset
spec:
  replicas: 3
  selector:
    matchLabels:
      app: user-pod
</code></pre>
<p>but when i execute the following command, it throws the foloowing error:</p>
<pre><code>kubectl create -f user-replicaset.yml 
 
&gt;error: error validating &quot;user-replicaset.yml&quot;: 
error validating data: ValidationError(ReplicaSet.spec.selector): 
unknown field &quot;app&quot; in io.k8s.apimachinery.pkg.apis.meta.v1.LabelSelector; 
if you choose to ignore these errors, turn validation off with --validate=false
</code></pre>
<p><strong>What's the problem? how can I solve this?</strong></p>

Mr-Programer
<p>you can't create replicaset without <code>spec.template.spec.containers</code> field. as this one is by default required to create replica-set in k8s. so you must need to add template field . and you can actually do what you want , just use your pod as here in template spec. template is the actual pod spec with which you are going to create your replica-set's pods.</p>
<p>this one is going to do the exact thing you are asking for:</p>
<pre><code>
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: user-replicaset
  labels:
    app: user-replicaset
spec:
  replicas: 3
  selector:
    matchLabels:
      app: user-pod
  template:
    metadata:
      labels:
        app: user-pod
    spec:
      containers:
      - name: user-container
        image: kia9372/store-user
</code></pre>
