<p>Is there a way to specify selector while creating service with kubectl directly like in command below ?</p>
<pre><code>    ~ $ kubectl create service clusterip headless-svc --tcp=80:80 --clusterip='None' --selector=&quot;app=multitool&quot; --dry-run -o yaml
Error: unknown flag: --selector
</code></pre>
<p>Obviously I can modify yaml file, e.g.</p>
<pre><code>    ~ $ kubectl create service clusterip headless-svc --tcp=80:80 --clusterip='None' --dry-run -o yaml
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    app: headless-svc
  name: headless-svc
spec:
  clusterIP: None
  ports:
  - name: 80-80
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: headless-svc
  type: ClusterIP
status:
  loadBalancer: {}
</code></pre>
<p>But Im curious if it possible to do during svc creation ?</p>
<p>Thank you !</p>

<p><code>kubectl create service</code> does not have an option to specify <code>selector</code> but you can use <code>kubectl expose</code> to create a service for deployment and specify <code>selector</code></p>
<pre><code>kubectl expose deployment nginx --port=80 --target-port=8000 --selector='app=multitool'
</code></pre>
