Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save xynova/7d18ccb44eb52a38b5b51c0922e06cc7 to your computer and use it in GitHub Desktop.
Save xynova/7d18ccb44eb52a38b5b51c0922e06cc7 to your computer and use it in GitHub Desktop.
Connecting Docker cli and Kubectl to Docker Desktop for Windows

Connecting Docker cli and Kubectl to Docker Desktop for Windows

Install Kubectl, Docker, Helm, etc

View details here: https://gist.github.com/xynova/87beae35688476efb2ee290d3926f5bb

Setup Docker

References:

  1. Open Docker settings dialog.

  2. Under general, tick the Expose daemon on tcp://localhost2375 option so that we can connect to Docker Daemon from the WSL Ubuntu VM. You can later explore options on how to secure the connection even further if you so desire: https://hub.docker.com/r/stefanscherer/dockertls-windows/.

  3. Make sure you share your C drive so that you can run containers with volumes

  4. Definitely give Docker Daemon more memory. Maybe 6GB or more?

  5. Enable Kubernetes (if you are not planning to use Minikube). Just tick the Enable Kubernetes option.

IMPORTANT: Make sure you select the docker-for-desktop context through the Docker Desktop for Windows menu so that the .kube/config file appropriately configured.

Configure Docker cli

Back in your WSL ubuntu session configure the cli to talk to the Docker Daemon:

echo "export DOCKER_HOST=tcp://localhost:2375" >> ~/.bashrc && source ~/.bashrc

Make sure connectivity to the Docker daemon work:

docker run --rm -ti hello-world

Configure Ubuntu to mount windows drives at /c or /e instead of /mnt/c or /mnt/e. The options = "metadata" line is not necessary but it will fix folder and file permissions on WSL mounts so everything isn’t 777 all the time within the WSL mounts:

cat << EOF | sudo tee /etc/wsl.conf
[automount]
root = /
options = "metadata"
EOF

NOTE: The previous action might take some time to propagate so a full Windows log-off or restart is required.

Once back, enter an ubuntu session:

ubuntu

# ubuntu@windows10:~$

Validate drives were mounted at the root:

ls "/c/Program Files"

Now lets run a sample container to make sure volumes are working

curl https://www.w3.org/Test/test > /c/index.html
docker run -ti --rm -p 2015:2015 -v /c/index.html:/srv/index.html abiosoft/caddy

You can now now browse to http://localhost:2015/ and should see a Test Dataset page.

Configure Kubectl

Find your user directory on windows

ls /c/users

Create a soft link to the .kube/config. Make sure you replace <YOUR_USER> with your username on windows:

mkdir -p ~/.kube
ln -sf /c/users/<YOUR_USER>/.kube/config ~/.kube/config

Now you should be able to connect to Kubernetes on Docker for Windows

kubectl cluster-info

# Kubernetes master is running at https://localhost:6445
# KubeDNS is running at https://localhost:6445/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
# 
# To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

Test kubectx

kubectx

# docker-for-desktop

Test kubens

kubens kube-system

# Context "docker-for-desktop" modified.
# Active namespace is "kube-system".

kubectl get pods

# NAME                                         READY   STATUS    RESTARTS   AGE
# etcd-docker-for-desktop                      1/1     Running   1          2h
# kube-apiserver-docker-for-desktop            1/1     Running   1          2h
# kube-controller-manager-docker-for-desktop   1/1     Running   1          2h
# kube-dns-86f4d74b45-z7n5h                    3/3     Running   3          2h
# kube-proxy-6568r                             1/1     Running   1          2h
# kube-scheduler-docker-for-desktop            1/1     Running   1          2h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment