Skip to content
🎉 Launch sale:50% off everything over $22 — automatically applied at checkout· ends Aug 2Shop the sale →
DevOps AI ToolKit
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.

Run this prompt with AI

Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.

Related prompts

More DevOps Security & Hardening prompts & error guides

Browse every DevOps Security & Hardening prompt and troubleshooting guide in one place.

Free download · 368-page PDF

Reading prompts? Get all 500 in one free PDF

500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.

  • 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
  • Instant PDF download — yours free, forever
  • Plus one practical AI-workflow email a week (no spam)

Single opt-in · unsubscribe anytime · no spam.