Create an Ingress Controller on a Cluster
Prerequisites
Configure Ingress Controller
Create deployments
Expose deployments
minikube addons enable ingress
kubectl create deployment web --image=gcr.io/google-samples/hello-app:1.0
kubectl expose deployment web --type=NodePort --port=8080
kubectl create deployment web2 --image=gcr.io/google-samples/hello-app:2.0
kubectl expose deployment web2 --port=8080 --type=NodePort
Accessing services with Ingress
Once we have the services to be routed by the ingress we define the file demo-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
rules:
- host: hello-world.info
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web
port:
number: 8080
- path: /v2
pathType: Prefix
backend:
service:
name: web2
port:
number: 8080
This file defines an Ingress with the path
hello-world.info
for the serviceweb
andhello-wold.info/v2
for the service web2
To test locally execute the following and copy the IP assigned to the Ingress we created
kubectl get ingress
Add the host and ip at the end of the file /etc/hosts
echo "192.168.59.114 hello-world.info" >> /etc/hosts
You can also just ssh into the cluster and test with curl
Reference Links
PreviousCommunicate two microservices in a Kubernetes clusterNextConfigure Kubernetes Horizontal Pod Autoscaler
Last updated