Scott Hanselman

How to set up Kubernetes on Windows 10 with Docker for Windows and run ASP.NET Core

January 30, '18 Comments [17] Posted in DotNetCore | Kubernetes | Open Source
Sponsored By

Docker for Windows is really coming along nicely. They have both a Stable and Edge channel and the Edge (beta, experimental) one just included a lovely new feature - Kubernetes support. Per their docs, Kubernetes is only available in Docker for Windows 18.02 CE Edge. They set most everything up nicely and put Kubectl into your path and setup a context. If you use kubectl for other things - like your own Raspberry Pi Kubernetes Cluster, then you'll need to be aware of switching contexts. Same thing applies if you have one in the cloud, like the Kubernetes Cluster I made in Azure AKS.

Got Docker for Windows? If you have not yet installed Docker for Windows, see Install Docker for Windows for an explanation of stable and edge channels, system requirements, and download/install information.

It's easy to get started, just click "Enable Kubernetes" and Docker for Windows will download and start the images you need. I clicked "show system containers" because I like to see what's hidden from me, but you decide for yourself. Do be aware - there's a TON.

Enabling Kubernetes in Docker for Windows

By default, you won't get the Kubernetes Dashboard - of which I'm a fan - so you may want to install that. If you follow the default instructions (and you're a noob like me) then you'll likely end up with a Dashboard that is pretty locked down. It can be somewhat frustrating to get access to your own development dashboard, so I use the alternative (read: totally insecure) dashboard, like this:

C:\> kubectl apply -f

I also like charts and graphs so I added these as well:

C:\> kubectl create -f
C:\> kubectl create -f
C:\> kubectl create -f

I can access the dashboard by default by running "kubectl proxy" then visiting this http://localhost:8001/ui and I'll get redirected to the dashboard:

Kuberenetes Dashboard

Now I can run through all the cool Kubernetes tutorials like the Guestbook Kubernetes Sample Application from the convenience of my Windows 10 machine. (I'm running a SurfaceBook 2 on the current non-Beta Windows 10.)

There are a lot of nice samples on running .NET Core and ASP.NET Core apps with Docker up at

I made a quick ASP.NET Core app called kubeaspnetapp:

C:\Users\scott\Desktop>dotnet new razor -o kubeaspnetapp
The template "ASP.NET Core Web App" was created successfully.
Restore succeeded.

Then added a two-stage build DockerFile that looks like this:

FROM microsoft/aspnetcore-build:2.0 AS build-env

# copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# build runtime image
FROM microsoft/aspnetcore:2.0
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "kubeaspnetapp.dll"]

And built and tagged the image with:

C:\Users\scott\Desktop\kubeaspnetapp>docker build -t kubeaspnetapp:v1 .

Then I create a quick Deployment that manages a Pod that runs the Container:

C:\Users\scott\Desktop\kubeaspnetapp>kubectl run kubeaspnetapp --image=kubeaspnetapp:v1 --port=80
deployment "kubeaspnetapp" created

Now I'll expose it to the "outside." Again, this is usually done with .yaml files but it's a good learning exercise and it's all local.

C:\Users\scott\Desktop\kubeaspnetapp>kubectl get deployments
kubeaspnetapp   1         1         1            1           1m

C:\Users\scott\Desktop\kubeaspnetapp>kubectl get pods
NAME                             READY     STATUS    RESTARTS   AGE
kubeaspnetapp-778f6d49bd-rct59   1/1       Running   0          1m

C:\Users\scott\Desktop\kubeaspnetapp>kubectl expose deployment kubeaspnetapp --type=NodePort
service "kubeaspnetapp" exposed

C:\Users\scott\Desktop\kubeaspnetapp>kubectl get services
NAME            TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
kubeaspnetapp   LoadBalancer   <pending>     80:31756/TCP     5s
kubernetes      ClusterIP      <none>        443/TCP          1d

Then I'll hit in my browser...note how that port is brokering to the internal port 80 where the app listens...and there's my ASP.NET Core app running locally on Kubernetes, set up with Docker for Windows. Nice.

My ASP.NET Core app running in Kubernetes local on my Windows 10 machine

Here's me getting the startup logs from that pod:

C:\Users\scott\>kubectl get pods
NAME                             READY     STATUS    RESTARTS   AGE
kubeaspnetapp-7fd7f7ffb9-8gnzd   1/1       Running   0          6m

C:\Users\scott\Dropbox\k8s for pi\aspnetcoreapp>kubectl logs kubeaspnetapp-7fd7f7ffb9-8gnzd
Hosting environment: Production
Content root path: /app
Now listening on: http://[::]:80
Application started. Press Ctrl+C to shut down.

Pretty cool. As all the tooling and things across Windows, Docker, Kubernetes, Visual Studio (all flavors) continues to get better and better, I can only imagine this experience will get better and better. I look forward to a time when I can freely mix containers from different OSs and easily push them all en masse to Azure.

Sponsor: Get the latest JetBrains Rider for debugging third-party .NET code, Smart Step Into, more debugger improvements, C# Interactive, new project wizard, and formatting code in columns.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb
Tuesday, 30 January 2018 11:59:52 UTC
For day to day use, I'd recommend leaving the "Show system containers (advanced)" checkbox unticked in Settings. It just shows the k8s control plane containers when you run
docker ps
which isn't very useful and can be confusing.
Tuesday, 30 January 2018 13:04:58 UTC
Another great post to start dig more about Kubernetes and Docker on Windows...
Tuesday, 30 January 2018 14:51:57 UTC
Getting an error for the dasboard setup and UI url not found.
kubectl apply -f
serviceaccount "kubernetes-dashboard" configured
role "kubernetes-dashboard-minimal" configured
rolebinding "kubernetes-dashboard-minimal" configured
service "kubernetes-dashboard" configured
The Deployment "kubernetes-dashboard" is invalid: spec.template.metadata.labels: Invalid value: map[string]string{"k8s-app":"kubernetes-dashboard"}: `selector` does not match template `labels`
Tuesday, 30 January 2018 15:03:32 UTC
After running
kubectl proxy
that starts the UI proxy server on I was able to see the Kubernetes UI
Tuesday, 30 January 2018 16:02:08 UTC
Thanks for the post.

I am unable to deploy the local image. However, when I pushed the image to docker hub, deployment got successful.

Muhammad Abdul Rehman
Wednesday, 31 January 2018 00:32:58 UTC
Sweet writeup Scott! You should do something similar for creating/using ACS clusters with Windows nodes. There isn't much out there on using ACS with Windows and your take on it would be hugely helpful.
Wednesday, 31 January 2018 06:25:42 UTC
Nice works, however I wanted a more detail information on baremetal/VM based master w/ Windows 2016 VM based node. If you have one please share!
Wednesday, 31 January 2018 22:14:07 UTC
nice post! check out my marka tescil blog
Thursday, 01 February 2018 02:34:52 UTC
Great news! Thanks you.
Thursday, 01 February 2018 11:37:55 UTC
Good information thanks a lot
Thursday, 01 February 2018 13:11:52 UTC
good post
imo for pc
thanks admin
Thursday, 01 February 2018 19:06:46 UTC
articles that are so helpful
gadai bpkb mobil
thank you admin
Friday, 09 February 2018 18:34:16 UTC

Nice post , I can copy this post and translate to spanish to my forum?

Thank you,

This is the forum :
Friday, 09 February 2018 22:42:46 UTC
Could this be set up to work in local network environments? For example, can I set up, say four, workstations(Computers) setting one as Master node and the others as worker nodes and configure kubernetes in docker for windows to replicate images across the workstations just like it's possible in AKS? Just curious.
Sunday, 11 February 2018 12:02:21 UTC
Really useful info, Thanks for sharing with us. And i have to share my use whatsapp on windows pc post with all of you. Thanks...
Monday, 12 February 2018 09:31:42 UTC
want to check intermediate and ssc 10th results from Manabadi 2018
Tuesday, 13 February 2018 15:15:46 UTC
Your blog looks very useful to me, I'll probably keep this link here to always be able to return to you
Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.