A Pod is not reachable from the internet without additional configuration. A NodePort Service opens a port on every cluster node and routes incoming traffic to selected Pods. It is a quick way to expose and test an application without adding a cloud load balancer. section 8.3.2
Listing 8.5 K8s YAML manifest for an NGINX Service
apiVersion: v1 kind: Service metadata: name: first-service-nginx spec: type: NodePort ports: - port: 5050 targetPort: 80 nodePort: 30007 selector: app: my-nginx
In this NGINX Service manifest, nodePort 30007 is the port exposed on each node. The Service uses port 5050, forwards to port 80 on the Pod, and selects Pods labeled app: my-nginx. section 8.3.2
Traffic can arrive at any node and be routed to a selected Pod elsewhere in the cluster. A NodePort left unspecified is assigned automatically; the resulting nonstandard web port may need to appear in a browser address. section 8.5.1 section 8.5
Choose the Service type to match the traffic:
- Use NodePort for straightforward external access through a port on each node. section 8.3.2
- Use ClusterIP when traffic should stay inside the cluster. section 8.3.2
- Consider LoadBalancer when a cloud-managed load balancer and its static public IP are useful, particularly for multiple Services and custom domains. section 8.5 section 8.5.1





