2.5 KiB
2.5 KiB
CKS-002 — NetworkPolicy two-sided isolation
Status: Fresh mastery attempt — awaiting learner answer
Domain: Cluster Setup (15%)
Topic: NetworkPolicy and cluster-level network restriction
Target time: 15 minutes
Difficulty: Harder than CKS
Scenario
Use context:
kubectl config use-context secure-prod
Namespace blue contains:
| Pod | Labels | Listens on |
|---|---|---|
web-0 |
app=web |
TCP 443 |
api-0 |
app=api |
TCP 8080 |
batch-0 |
app=batch |
none |
Additional facts:
- Namespace
edgehas labelzone=trusted-edge; its approved clients have labelrole=proxy. - Namespace
monitoringhas labelpurpose=metrics; its approved clients have labelrole=scraper. - Cluster DNS Pods are in
kube-systemwith labelk8s-app=kube-dns. - The internal database range is
10.40.0.0/16, but subnet10.40.8.0/24is reserved and forbidden. - Future unlabeled Pods may be added to namespace
blue.
Required end state
Create Kubernetes NetworkPolicy resources in namespace blue so that:
- Every current and future Pod in
blueis default-denied for both ingress and egress. - Only
role=proxyPods from thezone=trusted-edgenamespace may reachapp=webon TCP443. - Only
app=webPods inbluemay reachapp=apion TCP8080. - Only
role=scraperPods from thepurpose=metricsnamespace may reach bothwebandapiPods on TCP9100. - Only
webandapiPods may query cluster DNS over both UDP and TCP53. - Only
apiPods may connect to10.40.0.0/16on TCP5432, excluding10.40.8.0/24. batchPods must have no ingress or egress. No other traffic is permitted.- Do not modify existing Pods, namespaces, labels, or Services. Use standard Kubernetes
NetworkPolicyonly.
Section B — scored implementation
Section B is the only scored section. Write all required manifests below.
# Replace this comment with your complete NetworkPolicy manifests.
Optional self-check — unscored
- An empty-selector policy covers future unlabeled Pods.
- Every cross-namespace peer requires the correct namespace and Pod labels together.
- The
web → api:8080path is permitted in both relevant policy directions. - DNS does not become available to
batchor future unlabeled Pods. - The reserved database subnet remains unreachable.
- No rule accidentally opens all ports or all sources.
When ready, save this file and tell the teacher: Grade CKS-002 fresh attempt.