Kubernetes - Ingress
Kubernetes Service can expose deployments to the external world. However it can’t route requests to services base on HTTP URI. Kubernetes Ingresss solves this problem.
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. Ingress also provides SSL termination.
Ingress Demo
Enable Nginx Ingress controller
1 | $ minikube addons enable ingress |
Create deployment with name ‘web’ and expose it as a service
1 | $ kubectl run web --image=gcr.io/google-samples/hello-app:1.0 --port=8080 |
Create deployment with name ‘web2’ and expose it as a service
1 | $ kubectl run web2 --image=gcr.io/google-samples/hello-app:2.0 --port=8080 |
Execute kubectl get services
to verify both services are created.
1 | $ kubectl get services |
Create Ingress.yaml that defines an Ingress. Path /v1/* routes to the first service. Path /v2/* routes to the second service.
1 | apiVersion: networking.k8s.io/v1beta1 |
get minikube cluster ip
1 | $minikube ip |
add the following route to /etc/hosts
1 | 192.168.99.112 hello-world.info |
Create the Ingress resource
1 | kubectl apply -f example-ingress.yaml |
Access services ‘web’ with url http://hello-world.info/v1
1 | $ curl http://hello-world.info/v1 |
Access service ‘web2’ with url http://hello-world.info/v2
1 | $ curl http://hello-world.info/v2 |
Ingress Controller
Ingress resource relies on Ingress controller to work. You can choose ingress controller implementation that works best for you. Kubernetes support GCE, nginx. There are other Ingress Controllers available too. Istio provide its own ingress controller if you are using Istio. see Ingress Controller for more information.