Q-04 โ Ingress (CKA 2025)
๐ Question
Create a new Ingress resource named echo in the echo-sound namespace. Expose the Service echoserver-service on:
http://example.org/echo
using Service port 8080. The command:
curl -o /dev/null -s -w "%{http_code}\n" http://example.org/echo
should return 200.
โ Why we will NOT use Regex here
The exam URL provided is:
http://example.org/echo
NOT:
http://example.org/echo/test
http://example.org/echo/anything/else
Since the URL contains no subpaths, Kubernetes expects a simple path rule.
Therefore:
โ NO regex required
โ NO capture groups required
โ NO (.*) patterns
โ Only /echo is matched
Regex is only used when the path must match dynamic segments, which is not the case here.
๐ฆ If the Ingress Controller is nginx (most common in exam)
Nginx does NOT automatically strip the prefix /echo. So the backend would receive:
/echo
But echo-server expects:
/
So we must add a rewrite annotation:
nginx.ingress.kubernetes.io/rewrite-target: /
โ Correct Ingress manifest (nginx)
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: echo
namespace: echo-sound
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: nginx
rules:
- host: example.org
http:
paths:
- path: /echo
pathType: Prefix
backend:
service:
name: echoserver-service
port:
number: 8080
๐ฉ If the Ingress Controller is Traefik
Traefik automatically strips the prefix /echo. So no rewrite annotation is needed.
โ Correct Ingress manifest (Traefik)
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: echo
namespace: echo-sound
spec:
ingressClassName: traefik
rules:
- host: example.org
http:
paths:
- path: /echo
pathType: Prefix
backend:
service:
name: echoserver-service
port:
number: 8080
๐ Full Lab Setup (Deployment + Service + Ingress)
This allows you to fully test the question.
1๏ธโฃ Namespace
apiVersion: v1
kind: Namespace
metadata:
name: echo-sound
2๏ธโฃ Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: echoserver-deployment
namespace: echo-sound
spec:
replicas: 1
selector:
matchLabels:
app: echoserver
template:
metadata:
labels:
app: echoserver
spec:
containers:
- name: echoserver
image: k8s.gcr.io/echoserver:1.4
ports:
- containerPort: 8080
3๏ธโฃ Service
apiVersion: v1
kind: Service
metadata:
name: echoserver-service
namespace: echo-sound
spec:
selector:
app: echoserver
ports:
- port: 8080
targetPort: 8080
4๏ธโฃ Ingress (Nginx version โ most likely for exam)
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: echo
namespace: echo-sound
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: nginx
rules:
- host: example.org
http:
paths:
- path: /echo
pathType: Prefix
backend:
service:
name: echoserver-service
port:
number: 8080
๐งช Testing
With DNS:
curl -o /dev/null -s -w "%{http_code}\n" http://example.org/echo
If it returns 200, you succeeded.
Without DNS (common in labs):
curl -o /dev/null -s -w "%{http_code}\n" -H "Host: example.org" http://NODE_IP:NODE_PORT/echo