NetworkPolicy
Prerequisites
# Launch the toolbox
ktbx desk
# Check your use kind-kind context
kubectx
#Launch initialization script
/home/k8s0/openshift-advanced/labs/3_policies/ex4-network.sh
# go to correct namespace
kubens network-k8s<ID>
Check that 3 pods have been created.
Play with network policy
Look at the official documentation and at the examples
Prevent all ingress connections
Add a rule which prevents all ingress connections in the namespace
Create network policy
Create a network policy to restrict ingress connection to pgsql-postgresql-0
. Only webserver
pod should be able to connect to pgsql-postgresql-0
on port 5432
.
Check network connections between pods
Using kubectl exec -n network-k8s0 external -- netcat -w 2 -zv pgsql-postgresql 5432
Reference
For more details, check the k8s-school NetworkPolicy lab.