Bird
Raised Fist0
Kubernetesdevops~20 mins

Ingress and egress rules in Kubernetes - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Ingress and Egress Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:00remaining
Understanding Kubernetes Ingress Purpose

What is the primary purpose of an Ingress resource in Kubernetes?

ATo schedule pods on specific nodes based on resource availability
BTo define firewall rules for controlling outbound traffic from pods
CTo manage persistent storage volumes for stateful applications
DTo control external access to services inside the cluster, typically HTTP and HTTPS routes
Attempts:
2 left
💡 Hint

Think about how users outside the cluster reach your applications.

💻 Command Output
intermediate
0:45remaining
Output of kubectl get ingress

What is the output of the command kubectl get ingress when no Ingress resources exist in the default namespace?

Kubernetes
kubectl get ingress
A
NAME   HOSTS   ADDRESS   PORTS   AGE
BError from server (NotFound): ingresses.networking.k8s.io "" not found
CNo resources found in default namespace.
D
NAME   HOSTS   ADDRESS   PORTS   AGE
my-ingress   *   192.168.1.1   80   5d
Attempts:
2 left
💡 Hint

Consider what Kubernetes shows when no matching resources exist.

❓ Configuration
advanced
1:30remaining
Egress Rule to Allow Outbound HTTP Traffic

Which NetworkPolicy YAML snippet correctly allows pods in the frontend label group to send outbound HTTP (port 80) traffic to any destination?

A
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-http-egress
spec:
  podSelector:
    matchLabels:
      role: frontend
  policyTypes:
  - Egress
  egress:
  - ports:
    - protocol: TCP
      port: 80
B
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-http-egress
spec:
  podSelector:
    matchLabels:
      role: frontend
  policyTypes:
  - Ingress
  ingress:
  - ports:
    - protocol: TCP
      port: 80
C
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-http-egress
spec:
  podSelector:
    matchLabels:
      role: frontend
  policyTypes:
  - Egress
  egress:
  - to:
    - ipBlock:
        cidr: 0.0.0.0/0
    ports:
    - protocol: UDP
      port: 80
D
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-http-egress
spec:
  podSelector:
    matchLabels:
      role: frontend
  policyTypes:
  - Egress
  egress:
  - ports:
    - protocol: TCP
      port: 443
Attempts:
2 left
💡 Hint

Remember that egress rules control outbound traffic and HTTP uses TCP port 80.

❓ Troubleshoot
advanced
1:30remaining
Diagnosing Ingress Not Routing Traffic

You created an Ingress resource, but external HTTP requests to your domain return 404 errors. Which is the most likely cause?

AThe pod labels do not match the Service selector
BThe Ingress controller is not installed or running in the cluster
CThe Service type is set to ClusterIP instead of LoadBalancer
DThe NetworkPolicy blocks all ingress traffic to the pods
Attempts:
2 left
💡 Hint

Think about what component handles Ingress routing.

✅ Best Practice
expert
2:00remaining
Best Practice for Securing Egress Traffic in Kubernetes

Which approach is considered best practice to secure egress traffic from pods in a Kubernetes cluster?

AUse NetworkPolicies to explicitly allow only required outbound traffic and deny all else by default
BAllow all egress traffic by default and rely on pod security policies for protection
CConfigure Ingress resources to filter outbound traffic from pods
DUse host firewall rules only, ignoring Kubernetes NetworkPolicies
Attempts:
2 left
💡 Hint

Think about the principle of least privilege for network access.

Practice

(1/5)
1. What do Ingress rules control in Kubernetes NetworkPolicies?
easy
A. CPU resource limits for pods
B. Incoming traffic to pods
C. Storage access for pods
D. Outgoing traffic from pods

Solution

  1. Step 1: Understand the role of Ingress rules

    Ingress rules specify which incoming network traffic is allowed to reach the pods.
  2. Step 2: Differentiate from Egress rules

    Egress rules control outgoing traffic, not incoming.
  3. Final Answer:

    Incoming traffic to pods -> Option B
  4. Quick Check:

    Ingress = Incoming traffic [OK]
Hint: Ingress means incoming traffic control [OK]
Common Mistakes:
  • Confusing ingress with egress
  • Thinking ingress controls resource limits
  • Mixing network traffic with storage access
2. Which of the following is the correct syntax to allow all incoming traffic from pods in namespace frontend using a NetworkPolicy ingress rule?
easy
A. ingress: - from: - namespaceSelector: matchLabels: name: frontend
B. egress: - to: - namespaceSelector: matchLabels: name: frontend
C. ingress: - to: - namespaceSelector: matchLabels: name: frontend
D. egress: - from: - namespaceSelector: matchLabels: name: frontend

Solution

  1. Step 1: Identify ingress rule syntax

    Ingress rules use ingress: with from: to specify allowed sources.
  2. Step 2: Confirm namespaceSelector usage

    Using namespaceSelector with matchLabels is correct to select pods in a namespace.
  3. Final Answer:

    ingress: - from: - namespaceSelector: matchLabels: name: frontend -> Option A
  4. Quick Check:

    Ingress uses 'from' to allow incoming traffic [OK]
Hint: 'ingress' with 'from' allows incoming traffic sources [OK]
Common Mistakes:
  • Using 'to' instead of 'from' in ingress
  • Confusing ingress with egress syntax
  • Misplacing namespaceSelector under egress
3. Given this NetworkPolicy snippet, what traffic is allowed?
egress:
  - to:
    - ipBlock:
        cidr: 10.0.0.0/24
        except:
        - 10.0.0.5/32
medium
A. All outgoing traffic to 10.0.0.0/24 except 10.0.0.5
B. All incoming traffic from 10.0.0.0/24 except 10.0.0.5
C. All outgoing traffic to 10.0.0.5 only
D. All incoming traffic from 10.0.0.5 only

Solution

  1. Step 1: Analyze egress rule with ipBlock

    The rule allows outgoing traffic to IPs in 10.0.0.0/24 except 10.0.0.5.
  2. Step 2: Confirm direction and exceptions

    Egress means outgoing traffic; 'except' excludes 10.0.0.5 from allowed IPs.
  3. Final Answer:

    All outgoing traffic to 10.0.0.0/24 except 10.0.0.5 -> Option A
  4. Quick Check:

    Egress with ipBlock except excludes IPs [OK]
Hint: Egress 'to' with ipBlock allows excepted IPs blocked [OK]
Common Mistakes:
  • Confusing ingress with egress direction
  • Misreading 'except' as allowed IP
  • Mixing incoming and outgoing traffic
4. You wrote this NetworkPolicy egress rule but pods still cannot reach external IPs:
egress:
  - from:
    - ipBlock:
        cidr: 0.0.0.0/0
What is the error?
medium
A. NetworkPolicy must not have egress rules
B. CIDR 0.0.0.0/0 is invalid
C. Missing 'ports' section
D. Egress rules use 'to', not 'from'

Solution

  1. Step 1: Check egress rule syntax

    Egress rules specify destinations with 'to', not 'from'. Using 'from' is invalid here.
  2. Step 2: Understand correct usage

    Correct egress syntax uses 'to' to define allowed outgoing IP blocks.
  3. Final Answer:

    Egress rules use 'to', not 'from' -> Option D
  4. Quick Check:

    Egress uses 'to' for destinations [OK]
Hint: Egress rules always use 'to' keyword [OK]
Common Mistakes:
  • Using 'from' in egress rules
  • Assuming CIDR 0.0.0.0/0 is invalid
  • Thinking ports are always required
5. You want to restrict pods to only receive traffic from pods in the same namespace and send traffic only to a specific external IP range 192.168.1.0/24. Which NetworkPolicy configuration achieves this?
hard
A. ingress: - from: - podSelector: {} egress: - from: - ipBlock: cidr: 192.168.1.0/24
B. ingress: - from: - namespaceSelector: {} egress: - to: - ipBlock: cidr: 10.0.0.0/24
C. ingress: - from: - podSelector: {} egress: - to: - ipBlock: cidr: 192.168.1.0/24
D. ingress: - to: - podSelector: {} egress: - to: - ipBlock: cidr: 192.168.1.0/24

Solution

  1. Step 1: Configure ingress to allow same-namespace pods

    Using podSelector: {} allows traffic from all pods in the same namespace.
  2. Step 2: Configure egress to allow only specific external IP range

    Egress uses to with ipBlock for 192.168.1.0/24 to restrict outgoing traffic.
  3. Final Answer:

    ingress: - from: - podSelector: {} egress: - to: - ipBlock: cidr: 192.168.1.0/24 -> Option C
  4. Quick Check:

    Ingress 'from' podSelector + Egress 'to' ipBlock [OK]
Hint: Ingress uses 'from' podSelector; egress uses 'to' ipBlock [OK]
Common Mistakes:
  • Using 'from' in egress rules
  • Using namespaceSelector instead of podSelector for ingress
  • Mixing 'to' and 'from' keywords incorrectly
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard