Table Of Content
Part 1: Intro to containers, Kubernetes and DevOps
Part 2: Getting started (setting up my dev environment)
Part 4: Deploy to k8s in the cloud (Azure Kubernetes Service – AKS) and debug from VSCode
Part 5: Set up CI/CD pipeline for Kubernetes using DevOps best practices
Part 6: Debugging generic Kubernetes Clusters with Draft (coming soon)
Getting Started
The first thing I needed to do was set up a development environment. Since I was going to do container dev, I knew I could do this on Windows, Mac or Linux. At the moment i started this adventure, I only had access to my Windows machine and of course Azure. I figured I would first start with creating a dev environment for Windows and after playing around with that for a bit, I’d recreate everything on Linux. For this blog, we’ll just look at Windows and we’ll circle back around to Linux later in the series.
No matter the OS, the pieces I needed were going to be the same. I needed Docker for containers. I needed some sort of Kubernetes cluster locally. I needed Helm to do container package management. And finally Draft, so Draft could make my development cycle easier by handling all the kubernetes/helm nonsense for me. And logically, I would need to install everything in this order. Piece of cake right? How hard could this be? lol….
The first time I did this, I installed Minikube as my local Kubernetes cluster. However, Minikube was being wonky so instead of Minikube, I used Docker Edge, which includes Kubernetes and everything worked smoothly.
Setting up my windows dev environment
Install Chocolatey
Chocolatey is a package manager for Windows and it makes life easier when you have to install a bunch of stuff. Go to https://chocolatey.org and just follow the install directions. Or
- Bring up an Admin power shell console
- Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString(‘https://chocolatey.org/install.ps1’))
Install Docker Edge
Installing Docker Edge for windows is straight forward with chocolatey.
Turn on Hyper-V
Docker does require hyper-v to be turned on so let’s do that.
- From the start search text field thing, I typed in Turn Windows Features on or off
- Make sure Hyper-V is selected
Install Docker Edge
- From and Admin powershell command prompt, type in cinst docker-for-windows –pre –y
- After the install, docker doesn’t launch automatically, so from start, look for Docker for windows and launch it
- Window should pop up with Docker is now up and running
- Now we need to enable Kubernetes in the settings for Docker Edge, right click the little whale in the task bar and select Settings
- Click Kubernetes, check Enable Kubernetes and Show system containers (advanced) and click Apply
- This takes a while to run so kick back and relax for a bit.
Configure kubectl to point to this Kubernetes cluster
If you are installing this and haven’t used kubectl (the kubernetes client command line tool), it should be automatically configured to connect to your Kubernetes cluster in Docker Edge. Earlier, I installed and configured Minikube so I need change the context so kubectl is pointing to this Kubernetes cluster.
- From an Admin powershell console, kubectl config get-contexts
Notice I already installed minikube and it’s currently configured to use minikube - kubectl config use-context docker-for-desktop
Install Helm
Install Draft
At the time of this blog post, Draft wasn’t working for windows so i decided to use WSL (Windows Subsystem for Linux) and install Draft for Linux. This also meant that I had to configure my WSL environment to connect to my Kubernetes cluster from within WSL. So I had to install kubectl in WSL and then configure it to connect to my Docker Edge Kubernetes instance on windows.
When I first published this blog, I wrote a bunch of steps to install and configure kubectl in WSL. @nunixtech pointed out a MUCH easier way to do this so I updated my blog with his simple steps! I kept the old steps around for posterity. Also, if you need to tweak the paths in the config if you happen to use Minikube, those old steps might be useful. But using Docker Edge, here is the much simpler way.
Copy and tweak kubectl config files to Temp
First, I got my configuration files for kubectl ready by copying it to my temp directory and then tweaking the line endings for unix.
- From Admin powershell, copy $env:UserProfile/.kube/config $env:TEMP/kubectl-config
- Get-ChildItem -File -Filter *-config | % { $x = get-content -raw -path $_.fullname
; $x -replace “r
n”,”`n” | set-content -path $_.fullname }
Install and configure kubectl in WSL
Next I opened up WSL, installed kubect. Then, from WSL, i tweaked the config files in my windows temp directory by normalizing the path character, moved the files from my windows temp directory into the the correct .kube and .minikube directory. Then configured kubectl (in WSL) to connect to my windows Minikube
Next I opened up WSL, installed kubectl. After that, I needed to configure the kubectl from within WSL to connect to my Docker Edge Kubernetes instance. Because the configuration for Docker Edge didn’t require any paths to certificates (that would require me to tweak those paths for linux and to copy those certs over to WSL), I could just create and linked ~/.kube directory to my .kube directory on the windows side (C:/User/abel/.kube).
- From WSL, install kubectl, make it executable and then move it to /usr/local/bin
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
- cd to windows temp directory, tweak the temp config files by normalizing directory paths
cd /mnt/$(cmd.exe /c echo\|set /p=%TEMP% | sed --expression='s|\\|/|g' | sed --expression='s|^\([A-Za-z]\):|\L\1|')
- create a .kube in the home directory
mkdir ~/.kube - move configuration files to the right location in ~/
mv kubectl-config ~/.kube/config
- Convert windows paths to unix format
sed -i 's|\\|/|g' ~/.kube/config
sed -i 's|\([ "]\)\([A-Za-z]\):|\1/mnt/\L\2|' ~/.kube/config
- Create and link ~/.kube to the .kube directory on the windows side (this is the step @nunixtech suggested. See how step 6 replaces 2-5)
ln -s /mnt/$(cmd.exe /c echo\|set /p=%USERPROFILE% | sed 's/^./\L&\E/' | tr -d ':' | tr '\\' '/')/.kube ~/.kube
- Configure kubectl to connect to Docker Edge Kubernetes
kubectl config use-context docker-for-desktop - Make sure kubectl is configured correctly by launching sample app
kubectl run hello-minikube --image=k8s.gcr.io/echoserver:1.4 --port=8080
- Make sure deployment is working
kubectl get deployment
kubectl get pod
- Expose this service to the outside world
kubectl expose deployment hello-minikube --type=NodePort
kubectl get service hello-minikube
- Test everything by going back to windows, and browsing to localhost:<routed port>, so in my case, localhost:32048
Install Draft in WSL
- First make sure docker expose daemon on tcp://localhost:2375 without TLS by showing the hidden running icons and right clicking docker and selecting settings
- Make sure the Expose daemon checkbox is checked
- From WSL
export DOCKER_HOST=tcp://0.0.0.0:2375 curl -LO https://azuredraft.blob.core.windows.net/draft/draft-v0.14.1-linux-amd64.tar.gz
- tar -xvzf draft-v0.14.1-linux-amd64.tar.gz
- sudo mv linux-amd64/draft /usr/local/bin
- rm –r linux-amd64/
- rm draft-v0.14.1-linux-amd64.tar.gz
- draft init
Conclusion
If you followed all the steps in this blog, this should create your development environment for container based apps on a windows machine. We installed and configured Docker Edge (Docker + Kubernetes) on windows, Helm on windows, and Draft on WSL (because at this time, Draft is not working on windows) and configured Draft to connect to your kubernetes instance on windows. All the tooling involved in containers based development is in place and we are now ready to start writing our first container based app. In the next installment of this series, I will walk you through creating your first container based app and how to use all these tools in your development workflow.
And finally, if you found all these instructions to set up your Windows dev environment insane, you will be happy to know that Jessica Deen (@jldeen), Steven Murawski (@StevenMurawski) and I are creating a simple install script that will install and configure all this nonsense for you.
Next > My first app – Creating the asp.net core app, run in WSL, debug from VSCode
Hi Abel,
first thanks a lot for this serie, it’s always really helpful to have a full overview in one article.
As state in Twitter, actually if you just install k8s with Docker Edge, then in WSL you can simply link the .kube:
ln -s /mnt/c/Users/<Windows user/.kube ~/.kube
the default config is:
apiVersion: v1
clusters:
– cluster:
insecure-skip-tls-verify: true
server: https://localhost:6445
name: docker-for-desktop-cluster
contexts:
– context:
cluster: docker-for-desktop-cluster
user: docker-for-desktop
name: docker-for-desktop
current-context: docker-for-desktop
kind: Config
preferences: {}
users:
– name: docker-for-desktop
user:
client-certificate-data:…
Another addition, I wrote once a blog post for “securing” the Docker client from WSL to use TLS.
But here is a better and more concise take on it too:
https://raesene.github.io/blog/2018/03/29/WSL-And-Docker/
But this is just “tweaks”, you really did the hard lifting here and I do thank you very much for it 🙂
Looking forward for the next ones 🙂
WSL Corsair (@nunixtech)
This is awesome! Love it!!! Keep the tips coming. I am so new to Linux and containers. Weird to be a fish out of water again after all these years slinging code 🙂
Embarrassing confession, I just googled ln 🙂
haha … that’s a real strength to admit we do not know right (at least that’s why I tell myself as there’s so much I don’t know 🙂
Concerning step 6 here is “the Interop way”:
ln -s “
wslpath -u $(cmd.exe /c echo\|set /p=%USERPROFILE%)
/.kube” ~/.kubeshared knowledge can really be cool, it becomes a reusable command for any links. Thanks a lot for the cmd part (will be reading the final part now)
haha … that came out wrong, please note that there’s a “backtick” before wslpath and %) (it transformed the text in red.
Nice! my Linux-y bash knowledge is so bad. I just hack like a mad man until it works 🙂
So just a note if you are doing this all via PowerShell Command line that different flavors of Linux Subsystems can be run so keep in mind, whether you prefer Debian, Ubuntu, Kali or openSUSE
Thanks for your article…
Now, Draft is available for Windows:
choco install draft
Draft does not appear to be supported and no longer works with Helm;
Helm has removed Tiller causing Draft to throw errors related to Tiller….