HomeCKATopicsPractice tasks › Network Policy
CKA · Services & Networking

Network Policy

Look at the Network Policy YAML files in /root/exam_resources. Decide which of the policies provides the functionality to allow interaction between the frontend and the backend deployments in the…

Check live lab access → All CKA tasks

Live lab access

This task description is public. Live practice requires full access unless this is the selected free weekly task. See this week's free task.

Create an account to continue →

Read this week's free task →

On a phone? Read the task and create your account here, then sign in on a desktop or laptop for the terminal lab. Nothing starts until you choose Start.

The task

There are two deployments, Frontend and Backend.

Frontend is in the frontend namespace. Backend is in the backend namespace.

Task

Look at the Network Policy YAML files in /root/exam_resources.

Decide which of the policies provides the functionality to allow interaction between the frontend and the backend deployments in the least permissive way and deploy that YAML.

Original Prepium workshop · Tested on Kubernetes v1.35.8 on 8 September 2026; NetworkPolicy checks used Calico v3.32.2. Use a disposable cluster with a NetworkPolicy-enforcing CNI, such as Calico. A policy object can be accepted even when the installed network plugin does not enforce it.

Allow frontend traffic and prove that other traffic is denied

All three Pods below live in prepium-tutorial. The destination has label app=backend. The permitted source has app=frontend; the denied source has app=visitor. We test TCP port 80 directly against the backend Pod IP to keep DNS and Service routing out of the diagnosis.

frontend (app=frontend) ── TCP/80 allowed ──→ backend (app=backend)
visitor  (app=visitor)  ── TCP/80 denied  ──→ backend (app=backend)
namespace: prepium-tutorial

1. Establish a working baseline

kubectl create namespace prepium-tutorial
kubectl -n prepium-tutorial run backend --image=nginx:1.27-alpine --labels=app=backend
kubectl -n prepium-tutorial run frontend --image=busybox:1.36 --labels=app=frontend --command -- sleep 3600
kubectl -n prepium-tutorial run visitor --image=busybox:1.36 --labels=app=visitor --command -- sleep 3600
kubectl -n prepium-tutorial wait --for=condition=Ready pod --all --timeout=120s
BACKEND_IP=$(kubectl -n prepium-tutorial get pod backend -o jsonpath='{.status.podIP}')
kubectl -n prepium-tutorial exec frontend -- wget -T 3 -qO- "http://$BACKEND_IP"
kubectl -n prepium-tutorial exec visitor -- wget -T 3 -qO- "http://$BACKEND_IP"

Both requests must succeed before applying the policy. If the visitor was already blocked, its later timeout cannot prove this policy works. Diagnose the server, routing and other policies first.

2. Select the destination, then the allowed source

Save this as network-policy.yaml and apply it. The top-level podSelector chooses the protected backend Pods. The nested selector chooses which source Pods can connect.

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: backend-from-frontend
  namespace: prepium-tutorial
spec:
  podSelector:
    matchLabels:
      app: backend
  policyTypes:
    - Ingress
  ingress:
    - from:
        - podSelector:
            matchLabels:
              app: frontend
      ports:
        - protocol: TCP
          port: 80
kubectl apply -f network-policy.yaml
kubectl -n prepium-tutorial describe networkpolicy backend-from-frontend
kubectl -n prepium-tutorial exec frontend -- wget -T 3 -qO- "http://$BACKEND_IP"
kubectl -n prepium-tutorial exec visitor -- wget -T 3 -qO- "http://$BACKEND_IP"

The frontend should still receive the nginx page. The visitor should fail, commonly with a timeout and a nonzero exit status. Allow the CNI a short reconciliation interval and repeat with new requests. This policy limits ingress to selected Pods; it does not create an egress restriction.

3. Catch selector mistakes

The nested podSelector here matches source Pods in the policy's namespace. To allow only matching Pods in another namespace, put namespaceSelector and podSelector in the same from list entry. Putting them in separate entries broadens access because either entry may match.

Other policies are additive. If the visitor still succeeds, inspect all policies selecting the backend and confirm that enforcement is enabled. An additional allow-all policy can permit traffic that this policy does not explicitly allow.

Example requirementPassing evidence
Protect the intended PodsDestination selector matches app=backend
Keep legitimate trafficFrontend request succeeds on TCP 80
Restrict other sourcesVisitor request fails after a successful baseline

Variation: create another namespace with a Pod labelled app=frontend. Predict whether this policy allows it before testing. Do not widen the namespace selector until you can explain which sources it would add.

Cleanup: kubectl delete namespace prepium-tutorial. Reference: Kubernetes NetworkPolicy semantics. Next, try Pod-label troubleshooting or namespace isolation.

Exam
CKA
Domain
Services & Networking
Grading
Programmatic · partial credit

What this tests

Expose workloads with services and ingress, and restrict traffic with network policies. On the CKA exam, Services & Networking tasks are graded purely on what you build in the cluster - not multiple choice - so the only way to get faster is to do them on a real cluster against a clock.

Practice it for real

The public description lets you study the task before signing up. Full access includes this live lab; the selected Task of the Week is free with an account. You solve the task in a real terminal, hit validate, and a programmatic checker scores exactly what you got right and wrong (with partial credit). You can open the solution while practising, then retry and use the failed checks to improve your score.