Ingress: Routing
Ingress exposes HTTP and HTTPS routes from outside the cluster to services within the cluster. Traffic routing is controlled by rules defined on the Ingress resource.
*Kubernetes Official Docs
Ingress provides a single entry point that routes requests to different services based on:
Hostnames (e.g., app.example.com)
Paths (e.g., /api, /web)
TLS Settings (for HTTPS)
Annotations (for additional behavior like rewrites, redirects, etc.)
There are many use cases that utilize ingress such as TLS, Force HTTPS, Force Redirect, Basic Authentication, Rate Limiting, IP Whitelisting, etc. But for now lets focus on basic implementation that is for traffic routing.
Enable Minikube Ingress Addons
To enable ingress in minikube we need to enable the addons first.
To validate if ingress controller already running we can use command kubectl get pods -n ingress-nginx. It can take up to a minute before you see these pods running.
Create Ingress
Lets expose our simple-go service to outside using ingress we defined below. Create new file ingress.yaml and put the ingress definition there.
This will create ingress object with name simple-ingress using nginx. There are others ingressClassName such as Traefik, HAProxy, Istio, etc. But in this case we will use nginx.
In the rules section we can define rules for this ingress. An Ingress rule defines how incoming HTTP(S) traffic is routed inside a Kubernetes cluster.
host: Specifies which domain should match (optional).paths.path: Defines the URL path that should be routed.paths.pathType: Type of path matching (more details below). For full list of path type you can read further here: Path Type Example.backend.service.name: The name of the Kubernetes service to route traffic to.backend.service.port.number: The service port to forward traffic to.
So in our ingress definition we want to match all traffic for domain simple-go.mine to service with name simple-go and port 8080.
Lets apply our ingress definition and validate if on the list.
Test Ingress
Because I'm using MacOS (Minikube with Docker Driver) I need to do tunneling first using command minikube tunnel. It will tunnel all localhost traffic for port 80 and 443 to the minikube.
After tunneling started we then can access is using the curl command below.
You can try to change the path and domain to see what changes does it makes.
References
Last updated