The cluster was quiet, but the packets were restless. You can control that chaos with Kubernetes Network Policies. Combined with the precision of Zsh for scripting and automation, you get a fast, reliable way to define who talks to who inside your infrastructure.
What Are Kubernetes Network Policies?
Kubernetes Network Policies let you filter traffic between pods, namespaces, and external endpoints. They work at the IP address and port level within the cluster, enforced by the network plugin. You can allow or deny ingress (incoming) and egress (outgoing) traffic with exact rules. Without these policies, every pod can reach every other pod, which increases risk and noise.
Why Pair Network Policies with Zsh?
Zsh is a powerful shell for automating cluster operations. It supports advanced scripting, globbing, and aliases that make applying network policies faster and more consistent. You can script kubectl commands in Zsh to create, update, and audit policies across environments. This makes policy management reproducible and reduces human error.
Defining and Applying a Network Policy
A simple YAML example to allow ingress from one namespace:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-frontend
namespace: backend
spec:
podSelector:
matchLabels:
app: backend
ingress:
- from:
- namespaceSelector:
matchLabels:
name: frontend
policyTypes:
- Ingress
Automating with Zsh
Create a Zsh script for quick deployment: