Ingress with TLS
Author: Fabrice JAMMES (LinkedIn).
Objective
- Expose an application with an
Ingress, over HTTPS - Store a certificate and its key in a
Secretof typekubernetes.io/tls - Check which certificate the ingress controller serves, and disable plain HTTP
The CKS curriculum lists “Properly set up Ingress with TLS” in the Cluster setup domain.
Official documentation, available in the exam:
Setup
The cluster is shared by the trainees: the Traefik ingress controller is installed once for the whole cluster by the trainer. Do not install it yourself.
Info
Trainer only, once per cluster, before the lab. kind has no cloud load balancer: Traefik is exposed with a NodePort Service.
The demo-ingress repository holds the same setup as a script, and a version for OpenShift.
Each trainee works in a namespace of their own, with a host name of their own:
Deploy the application:
Exercise 1: the ingress controller
Which IngressClass is available? On which ports of the nodes does Traefik listen for HTTP and HTTPS?
Exercise 2: a certificate in a Secret
Create a self-signed certificate for $APP_HOST with openssl, then store it in a Secret named hello-tls.
Exercise 3: the Ingress with TLS
Create an Ingress hello of class traefik which sends https://$APP_HOST/ to the Service hello on port 8080, with the certificate of hello-tls. Use kubectl create ingress -h, or the documentation.
Then call the application with curl, without and with the certificate.
Tip
curl --resolve $APP_HOST:<port>:<ip> resolves $APP_HOST without /etc/hosts, and sends the right host name to the ingress controller (HTTP Host header and TLS SNI).
Exercise 4: which certificate is served?
Display the subject of the certificate served by Traefik for $APP_HOST, then for another host name, other.info. Explain.
Exercise 5 (beyond the exam): HTTPS only
Note
Beyond the CKS exam: entry points and annotations are specific to Traefik, and the Traefik documentation is not available in the exam. Keep the idea: a tls section does not disable plain HTTP, the controller decides. With ingress-nginx, whose documentation is available in the exam, an Ingress with TLS redirects HTTP to HTTPS by default (code 308), set by the annotation nginx.ingress.kubernetes.io/ssl-redirect.
Call the application over plain HTTP. Then make the Ingress answer only over HTTPS.
Tip
An entry point is a port Traefik listens on. List the entry points in the arguments of the traefik deployment, then look for the router.entrypoints annotation in the Traefik documentation of the Kubernetes Ingress provider.
Questions
- Where is the TLS connection terminated? Is the traffic between Traefik and the pod encrypted?
- How do you protect the private key of the certificate?