In the previous article, we deployed an ASP.NET Core 2.0 API app in AKS (Azure Managed Kubernetes). Now, let's quickly look into how to upgrade the application when there is a change in code. Please make sure you read the previous article to follow through this one.
Let's start with a code change in our previously created controller class. Just alter the position of the concatenated output from the 2nd Get method, move the machine name at the end.
- return Ok(ListOfQuotes.OrderBy(_ => r.Next(ListOfQuotes.Length)).Take(count).Select(x => $"{x}-{Environment.MachineName}"));
Once the controller is updated, let's create a new docker image locally with a new tag (consider this as a new version). Once done, you should be able to see the new image created with tag 'linuxV2'.
-
- docker build -t sanjaysrepo.azurecr.io/quotesgenerator:linuxV2 .
-
-
- docker images
Now, let's publish the same in our previously created Azure Container Registry (ACR). Make sure you are authenticated.
-
- az acr login --name sanjaysrepo
-
-
- docker push sanjaysrepo.azurecr.io/quotesgenerator:linuxV2
-
-
- az acr repository show-tags --name sanjaysrepo --repository quotesgenerator --output table
Cool! It's time to update our Kubernetes cluster deployment with this new image. Before we start, validate that you still have a deployment with 5 pods (spread across 2 VMs). To ensure maximum uptime, multiple instances of the application pod must be running, else as you can guess your app will go into offline mode as the only one pod is getting upgraded. Scale-up your pods (as you saw in the previous article) if you don't have more than one instance of the service running.
Now to upgrade your application please execute the following command. Also while the pods are being updated you can check the status of the pods by 'kubectl get pods' command. You can see how the pods restart themselves. At the end, after few moments all pods will be up and running again with the latest image.
-
- kubectl set image deployment quotes quotes=sanjaysrepo.azurecr.io/quotesgenerator:linuxV2
-
-
- kubectl get pods
While this was in progress quickly fire up Fiddler and hit the API URL as before 'http://your-public-ip/api/quotes/12'. Do it multiple times as quickly as possible, you can actually see that a few nodes that are not upgraded are still returning old formatted values, and a few nodes that are already upgraded are returning newly formatted values. This is so cool!
All done! We just successfully updated our code in the existing/running AKS cluster.