<p>I am trying to create a Service: NodePort for one of the pods I have deployed,</p>
<p><strong>Below is my service definition</strong></p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
  name: voting-service
  labels:
    name: voting-service
    app: demo-voting-app
spec:
  type: NodePort
  ports:
    - port: 80
      targetPort: 80
      nodePort: 30004
  selector:
    name: voting-app-pod
    app: demo-voting-app
</code></pre>
<p>I am deploying this service with command below</p>
<pre class="lang-sh prettyprint-override"><code>kubectl create -f voting-app-service.yaml 
</code></pre>
<p><strong>Here is the Error</strong></p>
<pre><code>The Service &quot;voting-service&quot; is invalid: spec.ports[0].nodePort: Invalid value: 30004: provided port is already allocated
</code></pre>
<p>So I tried to find services that are using port 30004 with netstat and lsof commands but couldnt find any services using that port.</p>
<pre class="lang-sh prettyprint-override"><code>➜  Voting-app kubectl create -f voting-app-service.yaml
The Service &quot;voting-service&quot; is invalid: spec.ports[0].nodePort: Invalid value: 30004: provided port is already allocated
➜  Voting-app sudo netstat -lntp | grep 30004     
➜  Voting-app lsof -i :30004                      
➜  Voting-app 
</code></pre>
<p>minikube version: v1.22.0
kubectl : 1.21 version</p>

Raja G
<p>As @HarshManvar mentioned you can change the port in the service file for one that isn't allocated.</p>
<p>Later you find that port <code>30004</code> was already allocated as there was a pod using that port:</p>
<blockquote>
<p>kubectl get svc | grep 30004</p>
</blockquote>
