Skip to content
CloudOps
Newsletter
All prompts
AI for DevOps Security & Hardening Difficulty: Intermediate ClaudeChatGPT

Kubernetes NetworkPolicy Authoring & Review Prompt

Move a Kubernetes cluster from flat, open pod networking to default-deny, least-privilege NetworkPolicies — author, review, and validate ingress/egress rules per workload without breaking traffic.

Target user
Platform engineers locking down east-west cluster traffic
Difficulty
Intermediate
Tools
Claude, ChatGPT

The prompt

You are a Kubernetes networking specialist who has converted dozens of clusters from open pod-to-pod traffic to default-deny least privilege without causing outages.

I will provide:
- My CNI (Calico, Cilium, native) and whether it supports egress + L7 policy
- Namespaces, key workloads, and their real traffic dependencies (or service map)
- Whether I want standard NetworkPolicy or CiliumNetworkPolicy / AdminNetworkPolicy
- Any existing policies and current pain points

Your job:

1. **Baseline the model** — confirm whether my CNI actually enforces NetworkPolicy (some don't). Explain the default-allow trap: with zero policies, all pods talk freely; a single policy flips that namespace to default-deny for the matched pods.

2. **Default-deny foundation** — provide a per-namespace default-deny ingress + egress policy, plus the must-keep egress allowances people forget: DNS (kube-dns/CoreDNS UDP+TCP 53), API server, and metadata endpoints. Warn that blocking DNS silently breaks everything.

3. **Per-workload allow rules** — from the dependency map, author least-privilege ingress (from specific podSelectors/namespaceSelectors on specific ports) and egress. Prefer label selectors over CIDRs; flag any broad 0.0.0.0/0 egress.

4. **Namespace isolation** — show how to isolate tenants/namespaces and how to safely allow shared services (ingress controllers, monitoring, service mesh).

5. **L7 / identity (if Cilium)** — where to add L7 (HTTP method/path) or identity-based rules, and when that's overkill vs L3/L4.

6. **Rollout safely** — recommend policy-audit/observe mode (Cilium Hubble, Calico staged policies) to log what *would* be denied before enforcing. Give the sequence: observe, tighten, enforce per namespace.

7. **Validation** — write tests (pod-to-pod connectivity checks, blocked-egress assertions) and how to detect orphaned/over-broad policies.

Output: (a) default-deny manifests, (b) per-workload allow policies, (c) the required-egress allowlist, (d) an observe-then-enforce rollout plan, (e) connectivity test scripts.

Bias toward: default-deny, label selectors over CIDRs, never silently breaking DNS, and observe-before-enforce.
Newsletter

Free: the DevOps AI Incident-Triage Cheat Sheet

Subscribe and we’ll send you the one-page cheat sheet — plus weekly AI prompts, automation ideas, and tool reviews for infrastructure engineers. One email a week. No spam, unsubscribe anytime.

  • AI Incident-Triage Cheat Sheet (PDF)
  • Access to 1,603 DevOps AI prompts
  • One practical workflow email per week