0
0
Kubernetesdevops~10 mins

Ingress and egress rules in Kubernetes - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to allow incoming HTTP traffic on port 80 in a Kubernetes NetworkPolicy.

Kubernetes
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-http
spec:
  podSelector: {}
  ingress:
  - ports:
    - protocol: TCP
      port: [1]
Drag options to blanks, or click blank then click option'
A443
B8080
C22
D80
Attempts:
3 left
💡 Hint
Common Mistakes
Using port 443 which is for HTTPS.
Using port 22 which is for SSH.
2fill in blank
medium

Complete the code to allow egress traffic to TCP port 53 for DNS resolution.

Kubernetes
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-dns-egress
spec:
  podSelector: {}
  egress:
  - ports:
    - protocol: TCP
      port: [1]
Drag options to blanks, or click blank then click option'
A53
B80
C443
D22
Attempts:
3 left
💡 Hint
Common Mistakes
Using port 80 or 443 which are for HTTP/HTTPS.
Using port 22 which is for SSH.
3fill in blank
hard

Fix the error in the NetworkPolicy to correctly specify ingress from pods with label app=frontend.

Kubernetes
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-frontend-ingress
spec:
  podSelector: {}
  ingress:
  - from:
    - podSelector:
        matchLabels:
          app: [1]
Drag options to blanks, or click blank then click option'
Abackend
Bfrontend
Cdatabase
Dcache
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong label values like backend or database.
Misspelling the label value.
4fill in blank
hard

Fill both blanks to allow egress traffic only to pods with label role=database on TCP port 5432.

Kubernetes
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-db-egress
spec:
  podSelector: {}
  egress:
  - to:
    - podSelector:
        matchLabels:
          role: [1]
    ports:
    - protocol: TCP
      port: [2]
Drag options to blanks, or click blank then click option'
Adatabase
Bfrontend
C5432
D80
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong label like frontend.
Using port 80 which is for HTTP.
5fill in blank
hard

Fill all three blanks to create an ingress rule allowing TCP traffic on port 443 only from pods with label tier=frontend in namespace 'web'.

Kubernetes
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-https-from-frontend
spec:
  podSelector: {}
  ingress:
  - from:
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: [1]
      podSelector:
        matchLabels:
          tier: [2]
    ports:
    - protocol: TCP
      port: [3]
Drag options to blanks, or click blank then click option'
Aweb
Bfrontend
C443
Dbackend
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong namespace or pod labels.
Using port 80 instead of 443.