CKAD Mock exam 7 - Q 12

Got this question wrong , the only difference between the solution provided and my yaml is that - port (ports is a list), I successfully created the network policy and it did not say any error in syntax. I used the yaml from k8s doc, where port is not - ports.

Need help to understand the difference between just ports and - ports.
Also once I have created the netpol what is the way to verify it’s working

Attached screenshots


k8s doc link to netpol : Network Policies | Kubernetes

Thanks!

Hi,

Using - ports means that all outgoing network traffic is allowed on port 53, no matter the destination. If a request goes to an external network using port 53, it will be allowed.

In your answer, where only port 53 is specified, it means that outgoing traffic is restricted to only reach pods in the ckad-beta namespace on port 53. Traffic to external networks would not be allowed.

About verify the netpol, you can either use an existing pod or create a new one in the ckad-alpha namespace. From there, use curl to try accessing the pod in the ckad-beta namespace.

Thanks for the explanation! Got it!