DEV Community

Ghassan Karwchan
Ghassan Karwchan

Posted on

1

How to fix common error using Azure Kubernetes AKS from WSL2

When you use Kubernetes CLI tool: kubectl that is installed while you installed Docker Desktop for Windows, there is a small glitch that it will fail the kubectl commands, because of Kubeconfig file.

Let's supposed you want to create a new cluster on AKS, as follows:

az aks create --resource-group MyResourceGropu --name MyMicroserviceCluster --node-count 1 --enable-addons http_application_routing --generate-ssh-keys
Enter fullscreen mode Exit fullscreen mode

And then you need to set that new cluster as your default cluster to work on, so you use

az aks get-credentials --resource-group MyMicroserviceResources --name MyMicroserviceCluster
Enter fullscreen mode Exit fullscreen mode

The previous command will retrieve the credentials of the newly created cluster and store it in the kubeconfig file, and make the newly cluster as the current default cluster, so any subsequent kubectl command will run against that cluster.

If you run the previous command from WSL2 terminal, you will get the following message:

Merged "MyMicroserviceCluster" as current context in c:\Users\<username>\.kube\config
Enter fullscreen mode Exit fullscreen mode

Because Kubernetes CLI tool is installed with Docker Desktop for windows, so it default the config location to windows location.

But later any subsequent kubectl command from WSL2 terminal, will use the linux path for kubeconfig which is ~/.kube/config.

So, if you run the following command:

kubectl config current-context
Enter fullscreen mode Exit fullscreen mode

you will see that the current context still the current context in linux config file, which most probably is the default docker-desktop.

To fix the problem, you can specify the config file as environment variable KUBECONFIG.

So modify the profile file ~/.profile by adding the following:

export KUBECONFIG=/mnt/c/Users/<windows user>/.kube/config
Enter fullscreen mode Exit fullscreen mode

This will point the config file to the windows config file.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay