Kubernetes Tutorial · Networking · Lesson 15 of 26
Ingress and the Gateway API
Route external HTTP traffic to Services by host and path, with TLS, through an Ingress controller or a Gateway.
Ingress
An Ingress routes HTTP(S) traffic by host and path to Services. It needs an Ingress controller (ingress-nginx, Traefik, a cloud load balancer controller) running in the cluster:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata: {name: shop}
spec:
ingressClassName: nginx
tls: [{hosts: [shop.example.com], secretName: shop-tls}]
rules:
- host: shop.example.com
http:
paths:
- {path: /api, pathType: Prefix, backend: {service: {name: api, port: {number: 80}}}}
- {path: /, pathType: Prefix, backend: {service: {name: web, port: {number: 80}}}}
Gateway API
The Gateway API (Gateway, HTTPRoute) is the newer, more expressive successor: roles are split between
platform teams (Gateways) and app teams (routes), and features like header matching and traffic splitting are
standard rather than controller-specific annotations.
cat > ingress.yaml <<'EOF'
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: shop
spec:
ingressClassName: nginx
rules:
- host: shop.example.com
http:
paths:
- path: /api
pathType: Prefix
backend:
service: {name: api, port: {number: 80}}
defaultBackend:
service: {name: web, port: {number: 80}}
EOF
kubeconform -strict -summary ingress.yaml
sed -i 's/pathType: Prefix/pathType: Startswith/' ingress.yaml
kubeconform -strict ingress.yaml 2>&1 | sed -E 's/.*(pathType)/ \1/' | head -2 || true
Output
Summary: 1 resource found in 1 file - Valid: 1, Invalid: 0, Errors: 0, Skipped: 0
Run this on your computer — see “Get Started” for setup.
See Ingress and Gateway API.
Test yourself
You applied an Ingress but nothing answers on the host. A likely cause?
Ingress objects are disabledNo Ingress controller is installed (or the ingressClassName doesn't match one)Services can't be used with IngressTLS is mandatory
Show answer
Answer: No Ingress controller is installed (or the ingressClassName doesn't match one)
The Ingress is only configuration; a controller implements it.