In this POC, We will do the following:
- Create an AKS cluster in Azure
- Deploy 2 simple services, helloworld and helloindia
- Create an nginx ingress controller which will route the traffic based on path, to the respective services
We will use the following two docker images for our POC. https://cloud.docker.com/u/spatnaik77/repository/docker/spatnaik77/helloworld https://cloud.docker.com/u/spatnaik77/repository/docker/spatnaik77/helloindia They are very simple rest APIs. helloworld returns "hello world" and helloindia returns "hello india"
Create an aks cluster from azure portal
Login to aks cluster using the following command:
az aks get-credentials --resource-group sidd-aks-poc-rg --name sidd-aks-poc-cluster
kubectl get nodes : Shows the node details of the cluster
NAME STATUS ROLES AGE VERSION
aks-agentpool-32009910-0 Ready agent 3h v1.11.5
aks-agentpool-32009910-1 Ready agent 3h v1.11.5
aks-agentpool-32009910-2 Ready agent 3h v1.11.5
Following configuration files will be used:
- helloindia-deployment.yaml - Deployment for helloindia
- helloindia-service.yaml - Load balancer for helloindia service
- helloworld-deployment.yaml - Deployment for helloworld
- helloworld-service.yaml - Load balancer for helloworld service
- ingress.yaml - defines the routing rules for the ingress controller Upload all the config files in the cloud shell
- kubectl apply -f helloworld-deployment.yaml
- kubectl apply -f helloworld-service.yaml
- kubectl apply -f helloindia-deployment.yaml
- kubectl apply -f helloindia-service.yaml
- kubectl get pods -o wide : Shows you total 6 pods (3 helloworld and 3 helloindia pods)
- kubectl get service helloworld : Shows you details about the load balancer for helloworld pods
- kubectl get service helloindia : Shows you details about the load balancer for helloindia pods
Sample output:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
helloworld LoadBalancer 10.0.192.9 40.122.113.115 80:30442/TCP 4m
siddharth@Azure:~$ kubectl get service helloindia
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
helloindia LoadBalancer 10.0.57.94 40.122.49.235 80:31822/TCP 4m
-
helm init
-
helm install stable/nginx-ingress --namespace kube-system --set controller.replicaCount=2 --set rbac.create=false
-
Verify the ingress controller just created kubectl get service -l app=nginx-ingress --namespace kube-system Sample output
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
wistful-pig-nginx-ingress-controller LoadBalancer 10.0.237.242 40.122.106.243 80:32173/TCP,443:30315/TCP 1m
wistful-pig-nginx-ingress-default-backend ClusterIP 10.0.161.4 80/TCP 1m -
try accessing the external ip: http://40.122.106.243 - You should see this message - "default backend 404"
Create nginx ingress route for routing the traffic to helloworld & helloindia service based on their path
kubectl apply -f ingress.yaml
- http://40.122.106.243/helloworld should return "Hello World"
- http://40.122.106.243/helloindia should return "Hello India"
az aks browse --resource-group sidd-aks-poc-rg --name sidd-aks-poc-cluster