Skip to main content

Lab 4.3 - Network Policies

Objectives

By the end of this lab, you will be able to:

  • Create Network Policies
  • Test network isolation
  • Understand the effect of policies

Exercise: Network Policy

Step 1: Create Pods

Create frontend and backend Pods with different labels.

Step 2: Create a Network Policy

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-frontend
spec:
podSelector:
matchLabels:
app: backend
policyTypes:
- Ingress
ingress:
- from:
- podSelector:
matchLabels:
app: frontend

Step 3: Test

Test connectivity with and without the Network Policy.


Lab created: December 2024