Azure Kubernetes Service Cheat Sheet

When Sitecore started moving towards Kubernetes I was pretty lost. Conceptually I understood how it worked, but when I started to actually work with sites in AKS (Azure Kubernetes Service) most of the basic tasks that took me seconds to do where no longer basic. One of the tasks was: how do I log into my servers? How to I check logs? How do I even log into AKS itself?! Well, if you’re in the same boat as I was you’re in luck, because I created a basic cheat sheet that I’ve been using and now you can have it too! 

Prerequisites

First thing we need to do is to install two command line tools

  • Azure CLI: My Kubernetes clusters are in Azure, so I need the CLI to log in. You can find the download link Here
  • Kubectl: CLI to run commands against Kubernetes clusters. You can download Kubectl here

Logging into the Cluster

First, you need to log into the cluster. Again, I am using Azure Kubernetes service, so I’m going to use the Azure CLI to log into my cluster. To do this I need two values: 

  • Resource group name
  • Kubernetes service name under the resource group

Then run the command in a command prompt window. This will open a browser to log into Azure:

az aks get-credentials --resource-group <RESOURCE GROUP NAME> --name <KUBERNETES SERVICE NAME>

Using Kubectl

Now that we are logged in we can start seeing the namespaces, pods and actually getting PowerShell prompts inside our pods.

Getting Namespaces

Depending on your implementation, your pods might be broken into namespaces. To see all namespaces run the following command:

kubectl get namespaces

Set Context to a Namespace

Sets the namespace for all kubectl commands

kubectl config set-context --current --namespace <YOUR NAMESPACE>

Get all pods

This commands gets all pods for your current namespace. The most common use case for me is to get the name of the Pod that hosts my CD, CM, Solr instances

kubectl get pods

Opening Powershell inside a pod

Once you get a list of all your pods, you would want to run a Powershell on a pod.

kubectl exec --stdin --tty <POD NAME> -- powershell

From here, you can run any PowerShell commands on the pods!

Copying files to host

Once I can access the pods via PowerShell, I usually want to take a look at the logs. But reading files with thousands of lines of logs is hard via PowerShell. To get around that, I download the logs to my host!

kubectl cp <YOUR POD NAME>:<PATH ON POD> <LOCAL PATH>

# Example: we have a pod name CD-ABC123. We want to copy the folder c:\inetpub\wwwroot\app_data\logs from the pod int c:\aks_logs\logs on our host

kubectl cp CD-ABC123:"\inetpub\wwwroot\app_data\logs" "\aks_logs\logs"

Hopefully this will help you getting started with Kubernetes in AKS!

1 thought on “Azure Kubernetes Service Cheat Sheet”

Leave a Comment