![]() |
VOOZH | about |
The Ingress Controller acts like a smart receptionist, routing traffic to the correct service, handling HTTPS, and balancing loads across Pods. With a single entry point, it simplifies traffic management, keeps services secure, and ensures smooth operation even as your applications scale.
It manages external access to services in a cluster. It evaluates Ingress resources, enforces routing rules, performs SSL/TLS termination, and can provide load balancing, authentication, and URL-based traffic routing.
Understanding the flow of an incoming request through the Ingress system is crucial for grasping the role of Ingress Controllers. Here's a simplified overview:
Let's explore a practical example using the Nginx Ingress Controller, one of the popular implementations.
Ensure you have kubectl configured to connect to your cluster.
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/cloud/deploy.yamlThis command deploys the Nginx Ingress Controller to your cluster.
Now, let's create a simple Ingress resource to route traffic to a specific service.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
namespace: default
spec:
rules:
- host: example.com
http:
paths:
- path: /app
pathType: Prefix
backend:
service:
name: app-service
port:
number: 80
In this example, any request to `example.com/app` will be directed to the `app-service` on port 80.
Apply this configuration to your cluster:
kubectl apply -f ingress.yamlExpected/Similar Ouput: ingress.networking.k8s.io/example-ingress created
You can now test the Ingress by sending a request to the specified host and path. Ensure you have the necessary DNS configurations or modify your local hosts file to map `example.com` to the cluster's IP address.
curl http://example.com/appapp-service.Ingress Controllers often provide the ability to terminate SSL/TLS encryption at the controller level, offloading the decryption process from individual services. This is achieved by specifying TLS settings in the Ingress resource.
apiVersion: v1
kind: Secret
metadata:
name: example-tls-secret
type: kubernetes.io/tls
data:
tls.crt: <base64-encoded-cert>
tls.key: <base64-encoded-key>
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
spec:
tls:
- hosts:
- example.com
secretName: example-tls-secret
rules:
- host: example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: app-service
port:
number: 80
Ingress Controllers support path-based routing, allowing you to direct requests to different services based on the specified paths. Additionally, URL rewrites can be configured to modify the requested path before forwarding it to the backend service.
...
paths:
- path: /v1
pathType: Prefix
backend:
service:
name: v1-service
port:
number: 80
...