In Kubernetes, that packet’s fate depends on your Network Policies. These rules define which Pods can talk to each other, and which connections are cut off. Without them, every Pod can send traffic anywhere. With them, you control the blast radius of any breach and lock down unexpected pathways.
kubectl is your direct line to configuring these boundaries. Network Policies are API objects stored in the cluster, and kubectl lets you create, inspect, and debug them fast. A simple policy starts with a manifest that declares kind: NetworkPolicy, targeting a set of Pods via labels. The spec then covers ingress or egress rules, with selectors for Pods, namespaces, and CIDRs.
Example:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: deny-all
namespace: default
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
Apply it with: