CKAD field manual

k8s Ingress YAML example

An Ingress is only rules. A controller (ingressClassName) implements them. The Service must already exist.

One living tower among identical black towers in the rain. One living tower among identical black towers in the rain.
Create
kubectl create ingress web --class=nginx --rule='web.example/=web:80'
Ingress
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: web
  namespace: default
spec:
  ingressClassName: nginx
  rules:
    - host: web.example
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: web
                port:
                  number: 80
Two paths
spec:
  ingressClassName: nginx
  rules:
    - host: web.example
      http:
        paths:
          - path: /api
            pathType: Prefix
            backend:
              service:
                name: api
                port:
                  number: 8080
          - path: /
            pathType: Prefix
            backend:
              service:
                name: web
                port:
                  number: 80

Fields

pathType
Required. Prefix matches /api and /api/foo. Exact is only that path.
number
backend.service.port.number — not servicePort.
ingressClassName
Picks the controller. No controller → the object sits there and nothing routes.

Watch

  • apiVersion is networking.k8s.io/v1. backend.service.port.number — not servicePort.
  • pathType is required. Prefix matches /api and /api/foo. Exact matches only that path.
  • No controller → the object sits there and nothing is routed. Set ingressClassName.

Official docs Ingress

Practice these objects on a live cluster →