Today I will try creation of a Kubernetes cluster but with Windows as nodes instead of Linux. Obviously Master will always be Linux. This time I will follow Deploy Kubernetes cluster for Windows containers step by step and then play with the newly created cluster. I advise you to read Part 1 before continuing.
Let’s start with the usual creation of a resource group for this test so that we can easily group all cloud artifacts in it and delete everything on the fly at the end. ARM has been a great addition to Microsoft Azure.
az group create --name myAcsWinTest --location westeurope
az acs kubernetes get-credentials --resource-group=myAcsWinTest --name=myK8sCluster --ssh-key-file ~/acs/sshkeys/acsivan
kubectl get nodes
Cluster up and running! Awesome!
Before proceeding, open Kubernetes Dashboard to check what’s going on in the cluster using a browser.
Let’s start with the easy sample of IIS using windowsservercore instead of nanocore as described in Microsoft article. I will follow same steps to introduce concepts like pods and way to expose it once manually deployed.
Note: I consider this bad because you end up with a pod, a service, but no controller between them as a Replica Set or a Deployment managing it. Later we will see how to “fix” this issue without downtime.
Create iis.json with following content:
We can now apply configuration to a new Pod named iis: kubectl apply -f iis.json
kubectl get pods --watch
It will take around 10 mins to be created, because windowsservercore image is quite big ~5GB. To gain time you can expose this pod right now, there is no need to wait for pod creation in this test. LoadBalancer creation will start immediately.kubectl expose pods iis --port=80 --type=LoadBalancer
(In a future post I will try Ingress in an hybrid cluster, let’s push Kubernetes to its limits!).kubectl get svc --watch
or check manually with Kubernetes Dashboard.When you have IP you can try to browse there and you should see:
Now let’s try to scale out our iis pod. Wait… We can’t scale a pod directly. We need a ReplicaSet or a Deployment for this. How would you handle this?
Here I use a trick I found during my research that let you scale your pods without any downtime for final users. Probably there is a better way to do it, if so please add it to the comment.
Brief Explanation needed
kubectl describe service iis
and you can see that service has a selector equal to “app=iis”. This means that any pod with this label will be exposed using this LoadBalancerThe idea here is to create a new deployment that will create 2 new replica of our iis pod using the same label.
kubectl create -f iisdeployment.yaml
kubectl get pods
now and you can see 1 running pod and 2 additional ones being created:Note: during these steps, you can check your service using a browser and see that is up and running without problems.
kubectl delete pods iis
kubectl scale deployments/iis replicas 4
What if we have a problem with a pod iis-1894189856–9fwsp and we want to isolate it from the rest while keeping it running for debugging purposes?
kubectl edit pods iis-1894189856-9fwsp
to the following content and save file:
kubectl exec -ti iis-1894189856-9fwsp powershell
In Part 3 I will try to create an hybrid cluster with Windows ad Linux nodes!
Do you want more information about Kubernetes on Azure? Contact us!