Bird
0
0

You wrote this NetworkPolicy but pods labeled role=frontend still cannot access app=nginx pods on port 80. What is wrong?

medium📝 Troubleshoot Q14 of 15
Kubernetes - RBAC and Security
You wrote this NetworkPolicy but pods labeled role=frontend still cannot access app=nginx pods on port 80. What is wrong?
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-nginx
spec:
  podSelector:
    matchLabels:
      app: nginx
  ingress:
  - from:
    - podSelector:
        matchLabels:
          role: frontend
    ports:
    - protocol: TCP
      port: 8080
AThe metadata name is incorrect
BThe podSelector is missing in the policy
CThe port in the policy is 8080 but nginx listens on port 80
DThe protocol TCP is not supported in NetworkPolicy
Step-by-Step Solution
Solution:
  1. Step 1: Compare port in policy with actual service port

    The policy allows ingress on TCP port 8080, but nginx usually listens on port 80.
  2. Step 2: Identify mismatch causing blocked traffic

    Because the port does not match nginx's listening port, traffic is blocked despite correct podSelector.
  3. Final Answer:

    The port in the policy is 8080 but nginx listens on port 80 -> Option C
  4. Quick Check:

    Port mismatch blocks traffic = D [OK]
Quick Trick: Check port numbers match service and policy exactly [OK]
Common Mistakes:
  • Ignoring port mismatch
  • Assuming protocol TCP is unsupported
  • Thinking metadata name affects traffic

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kubernetes Quizzes