A team is deploying a microservice that must be reachable within the cluster via a stable DNS name. They also need to distribute traffic among pods. Which Kubernetes resource provides both service discovery and load balancing?
Trap 1: ConfigMap
A ConfigMap is an API object for storing non-confidential key-value configuration data, such as environment variables, command-line arguments, or config file contents. It has no IP address, DNS name, or endpoint mechanism, and mounting it into a Pod does not make the Pod reachable to other components. Thus, while a ConfigMap might hold the microservice's settings, it cannot provide the network endpoint that the deployment requires.
Trap 2: Secret
A Secret is designed to hold sensitive information (e.g., passwords, tokens, keys) and is encoded in etcd; it is injected into Pods via volume mounts or environment variables. A Secret does not create any networking objects or assign any cluster-internal identity, so it cannot be used for service discovery or stable network addressing. Even though a Secret might contain connection details for another service, it does not itself make the microservice reachable.
Trap 3: Ingress
An Ingress is an L7 (HTTP/HTTPS) routing object that manages external access to Services, typically via path- or host-based rules through a controller (e.g., NGINX). It exposes web traffic from outside the cluster, but it does not create an internal stable IP/DNS entry for Pod-to-Pod communication within the cluster. Service discovery inside Kubernetes relies on the built-in Service object and DNS, not on Ingress.
- A
Service
A Service provides a stable virtual IP (ClusterIP) and a DNS record via the cluster's internal DNS (e.g., <service>.<namespace>.svc.cluster.local), so clients can resolve the backend without knowing individual Pod IPs. It uses label selectors to identify target Pods and load-balances traffic across them, which is precisely what this microservice needs for reliable internal reachability. This is the standard Kubernetes abstraction for service discovery within a cluster.
- B
ConfigMap
Why wrong: A ConfigMap is an API object for storing non-confidential key-value configuration data, such as environment variables, command-line arguments, or config file contents. It has no IP address, DNS name, or endpoint mechanism, and mounting it into a Pod does not make the Pod reachable to other components. Thus, while a ConfigMap might hold the microservice's settings, it cannot provide the network endpoint that the deployment requires.
- C
Secret
Why wrong: A Secret is designed to hold sensitive information (e.g., passwords, tokens, keys) and is encoded in etcd; it is injected into Pods via volume mounts or environment variables. A Secret does not create any networking objects or assign any cluster-internal identity, so it cannot be used for service discovery or stable network addressing. Even though a Secret might contain connection details for another service, it does not itself make the microservice reachable.
- D
Ingress
Why wrong: An Ingress is an L7 (HTTP/HTTPS) routing object that manages external access to Services, typically via path- or host-based rules through a controller (e.g., NGINX). It exposes web traffic from outside the cluster, but it does not create an internal stable IP/DNS entry for Pod-to-Pod communication within the cluster. Service discovery inside Kubernetes relies on the built-in Service object and DNS, not on Ingress.