<p>Here is my service.yaml code : </p>

<pre><code>kind: Service
apiVersion: v1
metadata:
  name: login
spec:
  selector:
    app: login
  ports:
  - protocol: TCP
    name: http
    port: 5555
    targetPort: login-http
  type: NodePort
</code></pre>

<p>I wrote service type as </p>

<pre><code>type: NodePort
</code></pre>

<p>but when i hit command as below it does not show the external ip as 'nodes' :</p>

<pre><code>'kubectl get svc'
</code></pre>

<p>here is output: </p>

<pre><code>NAME         TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
kubernetes   ClusterIP   10.100.0.1     &lt;none&gt;        443/TCP          7h
login        NodePort    10.100.70.98   &lt;none&gt;        5555:32436/TCP   5m
</code></pre>

<p>please help me to understand the mistake.</p>

aac
<p>There is nothing wrong with your service, you should be able to access it using <code>&lt;your_vm_ip&gt;:32436</code>.</p>

<p>NodePort, as the name implies, opens a specific port on all the Nodes (the VMs), and any traffic that is sent to this port is forwarded to the service. So, On your node port 32436 is open and will receive all the external traffic on this port and forward it to the login service.</p>

<p>EDIT:</p>

<p>nodePort is the port that a client outside of the cluster will "see". nodePort is opened on every node in your cluster via kube-proxy. With iptables magic Kubernetes (k8s) then routes traffic from that port to a matching service pod (even if that pod is running on a completely different node).</p>

<p>nodePort is unique, so 2 different services cannot have the same nodePort assigned. Once declared, the k8s master reserves that nodePort for that service. nodePort is then opened on EVERY node (master and worker) - also the nodes that do not run a pod of that service - k8s iptables magic takes care of the routing. That way you can make your service request from outside your k8s cluster to any node on nodePort without worrying whether a pod is scheduled there or not. </p>

<p>See the following article, it shows different ways to expose your services:</p>

<p><a href="https://medium.com/google-cloud/kubernetes-nodeport-vs-loadbalancer-vs-ingress-when-should-i-use-what-922f010849e0" rel="noreferrer">https://medium.com/google-cloud/kubernetes-nodeport-vs-loadbalancer-vs-ingress-when-should-i-use-what-922f010849e0</a></p>
