A developer needs to expose a deployment named 'web-app' running on port 8080 to external traffic. The cluster is on-premises with no cloud load balancer. Which service type should be used?
Trap 1: ExternalName
ExternalName maps a service to a DNS name (like an alias) by returning a CNAME record, with no selectors and no defined ports. It doesn't route traffic to pods or provide any port mapping, so a Deployment's pod IPs and container ports can never be reached through it. Therefore it cannot expose the 'web app' workload to clients, making it an invalid choice for this scenario.
Trap 2: ClusterIP
ClusterIP is the default Service type that assigns a stable virtual IP from the cluster's internal pool, load-balancing traffic to pod endpoints only within the cluster network. It is inaccessible from outside the cluster unless you add a NodePort, LoadBalancer, ingress controller, or port-forward, none of which are present. Thus a ClusterIP Service alone cannot provide external access to the web app, even though it is useful for internal communication.
Trap 3: LoadBalancer
LoadBalancer extends NodePort by requesting an external load balancer from the cloud provider (e.g., AWS ELB, GCP LB) via the service's 'type' field. On-premises or bare-metal clusters without a cloud controller manager cannot provision an external LB, and the service often remains in 'Pending' or merely falls back to NodePort behavior without actually creating a routable LB. Since the developer needs a reliable way to expose the deployment externally in a generic environment, LoadBalancer is only appropriate when a cloud provider integration is guaranteed, making it wrong in this unspecified context.
- A
ExternalName
Why wrong: ExternalName maps a service to a DNS name (like an alias) by returning a CNAME record, with no selectors and no defined ports. It doesn't route traffic to pods or provide any port mapping, so a Deployment's pod IPs and container ports can never be reached through it. Therefore it cannot expose the 'web app' workload to clients, making it an invalid choice for this scenario.
- B
ClusterIP
Why wrong: ClusterIP is the default Service type that assigns a stable virtual IP from the cluster's internal pool, load-balancing traffic to pod endpoints only within the cluster network. It is inaccessible from outside the cluster unless you add a NodePort, LoadBalancer, ingress controller, or port-forward, none of which are present. Thus a ClusterIP Service alone cannot provide external access to the web app, even though it is useful for internal communication.
- C
LoadBalancer
Why wrong: LoadBalancer extends NodePort by requesting an external load balancer from the cloud provider (e.g., AWS ELB, GCP LB) via the service's 'type' field. On-premises or bare-metal clusters without a cloud controller manager cannot provision an external LB, and the service often remains in 'Pending' or merely falls back to NodePort behavior without actually creating a routable LB. Since the developer needs a reliable way to expose the deployment externally in a generic environment, LoadBalancer is only appropriate when a cloud provider integration is guaranteed, making it wrong in this unspecified context.
- D
NodePort
NodePort is the simplest Service type that exposes an application to traffic from outside the cluster by opening a static port (default range 30000-32767) on every worker node's IP address. Traffic sent to any node's IP at that port is forwarded through the Service to the backing pod(s) selected by the Deployment, regardless of which node actually runs those pods. In the absence of a cloud-provider load balancer, NodePort works on any Kubernetes cluster and is precisely the mechanism that satisfies the developer's requirement to expose the web app externally.