Install the Ingress Controller
An Ingress Controller receives incoming HTTP and HTTPS traffic at a single external address and routes it to the services in the cluster based on hostnames and paths.
The centron and Kubernetes do not come with an Ingress Controller pre-installed. You must install it yourself within the cluster.
Why use an ingress controller?
Without Ingress, every externally accessible service requires its own NodePort – in other words, a separate port for each service, which you must make a note of and allow through the firewall.
With an ingress controller, a single entry point is sufficient for any number of HTTP services, which are distinguished by their hostnames and paths. In addition, it handles TLS termination centrally, meaning that certificates do not need to be managed within each individual application.
Prerequisites
- A cluster with the status Running
- A verified connection via
kubectl; see Connecting to the cluster - Helm installed
Ingress Controller traefik
The Traefik Ingress Controller is commonly used in Kubernetes. You can install it using the following configuration.
helm repo add traefik https://traefik.github.io/charts
helm repo update
helm install traefik traefik/traefik --version 35.3.0 \
--namespace my-traefik \
--create-namespace \
-f traefik-values.yaml
#traefik-values.yaml
ports:
websecure:
allowACMEByPass: true
forwardedHeaders:
trustedIPs:
- 10.1.1.0/24
- 10.0.0.1/32
- 127.0.0.1/32
- 192.168.0.0/16
proxyProtocol:
trustedIPs:
- 10.1.1.0/24
- 10.0.0.1/32
- 127.0.0.1/32
- 192.168.0.0/16
web:
forwardedHeaders:
trustedIPs:
- 10.0.0.1/32
- 10.1.1.0/24
- 127.0.0.1/32
- 192.168.0.0/16
proxyProtocol:
trustedIPs:
- 10.1.1.0/24
- 10.0.0.1/32
- 127.0.0.1/32
- 192.168.0.0/16
service:
enabled: true
loadBalancerSourceRanges:
- 0.0.0.0/0
type: LoadBalancer
annotations:
"service.beta.kubernetes.io/cloudstack-load-balancer-proxy-protocol": "true"
providers:
kubernetesCRD:
allowCrossNamespace: true
Determine external address
kubectl get service -n my-traefik
It takes a moment to allocate the address. As long as ‘<pending>’ is still shown in column EXTERNAL-IP, the address has not been allocated:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S)
traefik LoadBalancer 10.43.201.15 <pending> 80:30185/TCP,443:30359/TCP
You then need to add this address as an A record in your domain’s DNS.
Check the installation
kubectl get pods -n my-traefik
kubectl get ingressclass
The controller pod should have the status Running, and there should be an IngressClass named traefik.
Creating your first Ingress
This requires an existing deployment with an associated service – see Deploying the first image.We now need a Service of type ClusterIP and an Ingress.
For the service
apiVersion: v1
kind: Service
metadata:
name: web
labels:
app: web
spec:
type: ClusterIP
selector:
app: web
ports:
- name: http
protocol: TCP
port: 80
targetPort: 80
Enter the address you configured in DNS as the host in the Ingress object here:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: web-ingress
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: web
spec:
ingressClassName: traefik
rules:
- host: app.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web
port:
number: 80
How to use:
kubectl apply -f service.yaml
kubectl apply -f ingress.yaml
Check status:
kubectl get ingress
kubectl describe ingress web-ingress
Multiple services via a single ingress
This is precisely where the advantage over individual NodePorts lies – multiple hosts and paths share a single entry point:
spec:
ingressClassName: traefik
rules:
- host: app.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web
port:
number: 80
- host: api.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: api
port:
number: 8080
Troubleshooting
| Symptom | Possible cause |
|---|---|
| Controller unreachable | Check that the NodePorts are allowed through the firewall and that the node has a reachable address |
Request ends with 404 | The requested hostname does not match host in the Ingress |
Call ends with 503 | The referenced service or its pods are unreachable; check kubectl get endpoints <service-name> |
| Ingress has no address | ingressClassName is missing or does not match the installed IngressClass |
Controller logs:
kubectl logs deploy/traefik -n my-traefik -l app.kubernetes.io/component=controller
Next steps
Once the installation is complete, set up TLS encryption: