Bird
0
0

You want to expose a web app on port 80 inside the cluster and port 32000 externally using NodePort. Which YAML snippet correctly achieves this?

hard📝 Best Practice Q15 of 15
Kubernetes - Services
You want to expose a web app on port 80 inside the cluster and port 32000 externally using NodePort. Which YAML snippet correctly achieves this?
AapiVersion: v1\nkind: Service\nmetadata:\n name: webapp-service\nspec:\n type: ClusterIP\n selector:\n app: webapp\n ports:\n - port: 80\n targetPort: 80\n nodePort: 32000
BapiVersion: v1\nkind: Service\nmetadata:\n name: webapp-service\nspec:\n type: LoadBalancer\n selector:\n app: webapp\n ports:\n - port: 32000\n targetPort: 80\n nodePort: 80
CapiVersion: v1\nkind: Service\nmetadata:\n name: webapp-service\nspec:\n type: NodePort\n selector:\n app: webapp\n ports:\n - port: 32000\n targetPort: 32000\n nodePort: 80
DapiVersion: v1\nkind: Service\nmetadata:\n name: webapp-service\nspec:\n type: NodePort\n selector:\n app: webapp\n ports:\n - port: 80\n targetPort: 80\n nodePort: 32000
Step-by-Step Solution
Solution:
  1. Step 1: Match internal and external ports correctly

    The port is the internal cluster port (80), targetPort is the container port (80), and nodePort is the external port (32000).
  2. Step 2: Verify service type and port fields

    Service type must be NodePort and ports must be set accordingly to expose externally on 32000.
  3. Final Answer:

    YAML with type NodePort, port 80, targetPort 80, nodePort 32000 -> Option D
  4. Quick Check:

    NodePort type + nodePort 32000 + port 80 = correct setup [OK]
Quick Trick: Set port=internal, targetPort=container, nodePort=external port [OK]
Common Mistakes:
  • Swapping port and nodePort values
  • Using LoadBalancer or ClusterIP instead of NodePort
  • Setting nodePort outside allowed range

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kubernetes Quizzes