CodeBlanks Logo Icon CodeBlanks

Summary - Ingress

Combine host, path and TLS to write an Ingress.

Summary: Ingress

In this group:

  • An Ingress is a set of rules routing HTTP(S) traffic to Services by host and path; it provides a single entry point.
  • An Ingress controller (ingress-nginx, Traefik) applies the rules; ingressClassName chooses which one processes it.
  • YAML: networking.k8s.io/v1, rules[].host, paths[].path/pathType/backend.service.
  • Prefix and Exact matching; the longest prefix wins; defaultBackend is for unmatched requests.
  • TLS: spec.tls + a kubernetes.io/tls Secret; cert-manager gets certificates automatically.
kubectl get ing
curl -H "Host: magaza.example.com" http://$(minikube ip)/

Practice A complete Ingress

Write an Ingress YAML: name magaza; ingressClassName: nginx; under tls, host magaza.example.com and secretName: magaza-tls; for host magaza.example.com, the / path (Prefix) goes to port 80 of the web service.

Starter code

terminal
# buraya yaz

Sample solution

terminal
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: magaza
spec:
  ingressClassName: nginx
  tls:
    - hosts:
        - magaza.example.com
      secretName: magaza-tls
  rules:
    - host: magaza.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: web
                port:
                  number: 80

Expected output

ingress.networking.k8s.io/magaza created
$ curl -sI https://magaza.example.com | head -1
HTTP/2 200

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 If the Ingress's ADDRESS column stays empty, what is checked first?

  • The namespace quota
  • The etcd backup
  • Whether a controller is installed and ingressClassName matches Correct answer
  • The pods' image

Explanation: Check kubectl get ingressclass and the controller pods.

2 Use prefix matching.

Question
          - path: /api
            pathType: ____
Answer
          - path: /api
            pathType: Prefix

Explanation: Prefix is prefix matching by path segments.

3 Match.

Term Meaning
Ingress Rule
controller Enforcer
tls HTTPS
host Domain name

All lessons in Advanced