Consider a scenario where an application is deployed within a Kubernetes cluster, comprising three distinct components: frontend, backend, and a database. The Pod definition manifests for these pods are:
Assume default deny all NetworkPolicy has already been created in the test namespace, we would like to achieve the following configuration:
frontendpod should be allowed to communicate with thebackendpod only.backendpod should be allowed to communicate with thedatabasepod and thefrontendpod.databasepod should be allowed to communicate with thebackendpod only.
Create NetworkPolcies for each of these pods to achieve the scenario described above.
Hints:
- Please use the
IPaddresses (shown in the image above) of pods to define the theingressand theegressrules for the NetworkPolicies. - Remember in the context of defining
ingressoregressfor a pod in Kubernetes NetworkPolicy, theportsfield contains theportattribute. thisportattribute in the context ofingressrefers to the recipient's port while theportattribute in the context ofegressrefers to the destination'sport. - To define multiple manifests within a single YAML file, utilize the
---separator line between each manifest. This separator acts as a delimiter, allowing you to include several Kubernetes resource definitions, such as deployments, services, or config maps, in a single YAML document.