A Service has targetPort: http. The container defines:
ports:
- name: web
containerPort: 8080Connections through the Service fail. What is wrong?
- A.
Named ports are not allowed in
targetPort. - B.
containerPortmust be 80 for named ports to work. - C.
The container needs
hostPort: 8080. - D.
The Service refers to a named port
http, but the container's port is namedweb; usetargetPort: web(or8080).
Show answer and explanation
Answer: D
A named targetPort must match the port name defined in the Pod's container. Here the names differ, so no port resolves.
- Named target ports are supported.
- Any container port number may be named.
hostPortis not needed for Service routing.