In this post, we’ll walk you through deploying a Docker image on an Azure Kubernetes Service (AKS) cluster and testing it using cURL. This process involves creating a Docker image, registering it with the Azure Container Registry, pulling it onto a node, and using it for testing.
Prerequisites
- Azure CLI installed
- Docker installed
- Azure subscription with access to AKS
Step 1: Log in to Your Azure Account
To begin, log in to your Azure account using the Azure CLI:
az login
After logging in, you’ll see a list of subscriptions you have access to. Select the subscription associated with your AKS cluster.
Step 2: Create a Docker Image
We’ll create a simple Docker container with cURL installed. This will allow us to ping URLs from within the container.
Create a Dockerfile
with the following content:
FROM ubuntu:latest RUN apt-get update && apt-get install -y curl
Build the Docker image using the command:
docker build -t <acr_name>.azurecr.io/ubuntu-curl:0.1 .
Replace <acr_name>
with your Azure Container Registry (ACR) name.
Step 3: Push the Docker Image to Azure Container Registry
Next, log in to the ACR to push the Docker image:
az acr login --name <acr_name>
Once logged in, push the image to the registry:
docker push <acr_name>.azurecr.io/ubuntu-curl:0.1
Step 4: Connect to the AKS Cluster
Retrieve the credentials for your AKS cluster:
az aks get-credentials --resource-group <resource_group_name> --name <aks_cluster_name> --admin
Replace <resource_group_name>
and <aks_cluster_name>
with your resource group and cluster name.
Step 5: Debug a Node Using the Docker Image
To debug a node, use kubectl
to list the nodes in your cluster:
kubectl get node -o wide
This command will display the nodes in your cluster. Note the name of the node you wish to debug. Then, run the following command to create a debugging pod on that node using your Docker image:
kubectl debug node/<node_name> -it --image=<acr_name>.azurecr.io/ubuntu-curl:0.1
Replace <node_name>
with the name of your node and <acr_name>
with your ACR name.
You should see an output similar to:
Creating debugging pod node-debugger-aks-nodepool1-37663765-vmss000000-bkmmx with container debugger on node aks-nodepool1-37663765-vmss000000.
If you don’t see a command prompt, try pressing enter. root@aks-nodepool1-37663765-vmss000000:/#
Step 6: Test Connectivity Using cURL
With the pod running, you can use cURL to test connectivity:
curl <url>
Replace <url>
with the URL you wish to test.
Step 7: Clean Up
After completing your debugging, clean up the debugging pod to avoid unnecessary resource usage:
kubectl get pods
Find the pod with “debug” in its name and delete it:
kubectl delete pod <pod_name>
Replace <pod_name>
with the name of the debugging pod.
Conclusion
In this guide, we’ve walked through creating and deploying a Docker image to an AKS cluster, testing it using cURL, and cleaning up resources. This process is helpful for debugging and testing in Kubernetes environments.