{ "id": "network-policy", "title": "Isolate Traffic with NetworkPolicy", "category": "Networking", "difficulty": "Hard", "type": "task", "weight": 9, "description": "## Implement Network Isolation\n\nA pre-created `database` pod in the `netpol` namespace must only accept traffic from pods labeled `role=backend`.\n\n**Your tasks:**\n1. Create a **NetworkPolicy** named `db-isolate` in the `netpol` namespace that:\n - Targets pods with label `app=database`\n - Allows **ingress** only from pods with label `role=backend` in the **same namespace**\n - Denies all other ingress traffic\n2. Verify the policy is applied correctly\n\n> The `database` and `backend` pods are pre-created for you.", "hints": [ { "title": "Understand NetworkPolicy selectors", "body": "A NetworkPolicy uses `podSelector` to pick which pods it applies to, and `ingress.from` to define allowed sources.", "command": "kubectl explain networkpolicy.spec.ingress.from" }, { "title": "Write the NetworkPolicy", "body": "An empty ingress rule (no `from`) denies everything. Specifying a `from` allows only those sources.", "command": "cat <