-
Apply the namespace:
kubectl apply -f rbac/namespace.yaml
-
Apply RBAC configurations:
kubectl apply -f rbac/serviceaccount.yaml kubectl apply -f rbac/role.yaml kubectl apply -f rbac/rolebinding.yaml
-
Deploy the test pod:
kubectl apply -f rbac/test-pod.yaml
-
Apply Network Policies:
kubectl apply -f network-policies/default-deny-all.yaml kubectl apply -f network-policies/allow-internal-traffic.yaml kubectl apply -f network-policies/allow-web-traffic.yaml kubectl apply -f network-policies/allow-dns.yaml
- Namespace:
rbac-demois created to isolate RBAC configurations. - ServiceAccount:
demo-sais assigned limited permissions. - Role: Grants read-only access to pods and pod logs.
- RoleBinding: Binds the
demo-sato the definedRole. - Test Pod: Runs under the
demo-safor testing access control.
- default-deny-all.yaml: Denies all ingress and egress by default.
- allow-internal-traffic.yaml: Allows traffic within the namespace between all pods.
- allow-web-traffic.yaml: Allows ingress traffic to pods with label
role: webon ports 80 and 443. - allow-dns.yaml: Allows egress DNS queries (UDP port 53) to
kube-dnsinkube-systemnamespace.
- Ensure your Kubernetes cluster has a CNI plugin that supports NetworkPolicies (e.g., Calico, Cilium, Weave).
- Use
kubectl describeandkubectl logsfor troubleshooting. - Verify policies using
kubectl execand network connectivity tools likecurl,wget, ornslookupinside test pods.