Launching the simple application with Azure Kubernetes Service
In previous few blogs, we have explained about the Kubernetes and container orchestration. Microsoft Azure provides the hosted Kubernetes service. To create the basic Kubernetes Cluster on Azure please visit our previous blog.
In this blog, I will launch a simple application on Azure Container Service.
Pre-requisite
- Kubernetes Cluster
- Kubectl utility
- Deployment and Services in Kubernetes
- Azure CLI
Application: Hello World
This is a simple hello-world application. We will be creating the 5 deployments of the app and external load balancer service to access the app.
Before that please make sure Azure CLI is installed and kubectl is configured with your Kubernetes Cluster.
To make sure kubectl is configured with Azure K8S cluster use following command:
az aks get-credentials --name crK8sCluster --resource-group k8sResourceGroup
Modify --name
and according--resource-group
to the cluster configuration. (You will get this when you created the cluster)
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
aks-nodepool1-83648360-0 Ready agent 51d v1.7.7
Now the cluster is configured properly.
Let’s check deployment.yml for creating the application:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: hello-world
labels:
app: hello-world
ver: v1
spec:
replicas: 5
selector:
matchLabels:
app: hello-world
ver: v1
template:
metadata:
labels:
app: hello-world
ver: v1
spec:
containers:
- name: hello-world
image: kubejack/helloworld:latest
imagePullPolicy: Always
ports:
- containerPort: 3000
This is the deployment specifications for the hello-world application. And we exposed the app on container port.3000
But to access the app it is required to have external service.
For this, external load balancer service is required. The service will create the external load balancer on Azure and expose the application to the internet.
service.yml:
apiVersion: v1
kind: Service
metadata:
name: hello-world-svc
labels:
name: hello-world-svc
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 3000
protocol: TCP
selector:
app: hello-world
ver: v1
To know more the services please view our blog for services.
Let’s create the deployment and service:
kubectl create -f deployment.yml
and
kubectl create -f service.yml
You will get :
$ kubectl get po -o wide
NAME READY STATUS RESTARTS AGE IP NODE
bitcoin-core-deployment-2058282966-cwchl 1/1 Running 51 45d 10.244.0.7 aks-nodepool1-83648360-0
cr-development-jenkins-2645363986-99n88 1/1 Running 0 34d 10.244.0.22 aks-nodepool1-83648360-0
hello-world-493621601-brnw9 0/1 ContainerCreating 0 30s <none> aks-nodepool1-83648360-0
hello-world-493621601-h7qg1 0/1 ContainerCreating 0 30s <none> aks-nodepool1-83648360-0
hello-world-493621601-knsm5 0/1 ContainerCreating 0 30s <none> aks-nodepool1-83648360-0
hello-world-493621601-qjg7d 0/1 ContainerCreating 0 30s <none> aks-nodepool1-83648360-0
hello-world-493621601-tj379 0/1 ContainerCreating 0 30s <none> aks-nodepool1-83648360-0
After few seconds,
$ kubectl get po
NAME READY STATUS RESTARTS AGE
hello-world-493621601-brnw9 1/1 Running 0 1m
hello-world-493621601-h7qg1 1/1 Running 0 1m
hello-world-493621601-knsm5 1/1 Running 0 1m
hello-world-493621601-qjg7d 1/1 Running 0 1m
hello-world-493621601-tj379 1/1 Running 0 1m
All the pods will be in running state.
But to access the application we need to check if service exposed the load balancer and given the external IP or not.
$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-world-svc LoadBalancer 10.0.108.140 52.170.233.129 80:30558/TCP 1m
kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 51d
Here you can see the external IP exposed 52.170.233.129
.
Now its time to verify if the application is running on specified IP or not.
With the curl command lets check it:
$ curl http://52.170.233.129
Hello World!
It’s working. This is the simple way to launch the application with Azure Kubernetes Service.
To delete the application:
$ kubectl delete -f deployment.yml
$ kubectl delete -f service.yml
It will delete all resources that we have created so far.