Deploying Kubernetes Configuration to Azure AKS

The Kubernetes Deployment Configuration and the Bash Script to Tweak It.


This blog post describes the second part of my Azure Kubernetes Services (AKS) studies. In the first part “Creating Azure Kubernetes Service (AKS) the Right Way” I created a Terraform configuration for the project infra for the Azure cloud: AKS (the Kubernetes service itself), ACR (Azure Container registry) to host the Docker images and other related cloud infra I needed for the demo application.

  • The Simple Server Docker image project which can be found in my Github account.

Kubernetes Deployment Configuration

There are two Kubernetes configuration files: “simple-server-namespace-template.yml” and “simple-server-deployment-template.yml”. The configuration files are full of “REPLACE_SOMETHING” strings so that I could use the same configuration files to deploy two different versions of the same Simple Server: the single-node test version and the table-storage version (uses Azure Table Storage as database, see my previous blog post: “Azure Table Storage with Clojure”). The deployment configuration files also support two Kubernetes clusters: Minikube test Kubernetes cluster and Azure Kubernetes Service (AKS) Kubernetes cluster (which I created in my previous exercise and described in my previous blog post “Creating Azure Kubernetes Service (AKS) the Right Way”).

Deployment to Minikube

Minikube provides a local single node Kubernetes cluster that you can use for testing Kubernetes deployments. Install minikube using instructions in Minikube installation instructions. You also need to install the kubectl command line tool: kubectl installation instructions. I have earlier written some experiences using Minikube so I’m not going to reiterate those instructions again, see my blog post “Exploring Kubernetes with Minikube”. You can also read more detailed instructions in the project’s file.

./ single-node minikube 31111 0.1 dummy-acr
./ 31111

Deployment to Azure Kubernetes Service (AKS)

Deployment to Azure AKS was pretty much the same as with Minikube, except that you need to tag the Docker images and push them to the Azure Container Registry (ACR) so that AKS can pull the images from there. First login to the ACR so that you are able to push to it:

az acr login --name YOURACRNAME
docker images # => Check the initial tags first.
# Tag the base image first:
docker tag karimarttila/debian-openjdk11:0.1
# And then the demo image:
docker tag karimarttila/simple-server-clojure-single-node:0.1
docker images # => Check that you have the ACR tagged images.
docker images   # => Check the images you are about to push.
docker push
docker push
# => Check that the images are safely in your Azure ACR registry.
az acr repository list --name YOURACRNAME --output table
kubectl config use-context YOUR-AZURE-AKS-CONTEXT
./ single-node azure YOUR-PUBLIC-IP 31111 0.1 kari2ssaksdevacrdemo
./ azure-table-storage azure YOUR-PUBLIC-IP 31112 0.1 kari2ssaksdevacrdemo

Kubernetes Debugging Tricks

How to get an interactive shell to a running Kubernetes pod when the pod crashes and won’t start? I had to use this trick when I was wondering why the application couldn’t find one environmental variable in the pod — and the application crashed because of that and the pod crashed as well. So, first you have to override the Docker entrypoint in the Kubernetes deployment, use e.g. the following command right after image definition in the Kubernetes deployment yml file:

command: ["/bin/sh"]
args: ["-c", "while true; do echo hello; sleep 10;done"]
kubectl get pods --namespace $MY_NS  # => Get pod identifier, and use it in the next command:
kubectl exec -it kari-ss-table-storage-deployment-86b6d498ff-zdqq2 --namespace kari-ss-table-storage-ns /bin/bash


With little bash/sed tweaking you are able to create one Kubernetes deployment configuration and use it to deploy different versions of your application and also target to different Kubernetes clusters.

I’m a Software architect and developer. Currently implementing systems on AWS / GCP / Azure / Docker / Kubernetes using Java, Python, Go and Clojure.