.NET Apps on DC/OS

Weston Bassler
ITNEXT
Published in
5 min readJul 9, 2018

--

source: news.microsoft.com

Starting this post off with a major disclaimer.

Disclaimer: I am in no way shape or form a .NET developer, have any sort of experience running .NET apps nor am I advocating that you run .NET apps. But I am also not saying that you shouldn’t run .NET apps.

I do not consider myself a Microsoft fan boy, but I have really enjoyed some of the decisions that Microsoft has made over the last few years around being more involved in the open source community (Although I have to admit, like many others, I am a bit nervous about the Github acquisition). I do use Windows 10 on one of my personal machines and have absolutely fallen in love with VSCode. A few months ago, Microsoft announced that you are now able to run .NET apps in Docker.

“Most image repos provide extensive tagging to help you select both a specific framework version and an OS (Linux distro or Windows version).”

Awesome! Since we can run .NET apps in Docker and use a Linux distro, how about running these on one of our favorite container orchestrators such as DC/OS? In this short post, I’m going to demonstrate just how simple this actually is to do out of the box as well as provide you with the code to follow along and try yourself.

Again, I am not trying to advocate or not advocate for running .NET apps in general or in docker or on a container orchestration platform. This is about being able to provide more services and flexibility to your users on your favorite platform.

This whole thing came to me one afternoon when a friend I was visiting came to me and said, “Did you see that you can now run .NET apps in Docker? We should see if we can run it on DC/OS.”

At the time, I couldn’t tell if he was actually being serious or not. As far as I understood at the time, ANYTHING Windows container-based, required Windows OS. So I started reading the article that he sent to me and I realized that you could in fact run it on Nix based operating systems as well. Well done, MS team!

Started reading the Docker Hub docs for .NET Core and busted out the handy dandy Docker on Mac.

docker run -it --rm -p 8000:80 --name aspnetcore_sample microsoft/dotnet-samples:aspnetapp
Unable to find image 'microsoft/dotnet-samples:aspnetapp' locally
aspnetapp: Pulling from microsoft/dotnet-samples
683abbb4ea60: Pull complete
a7e581c00d24: Pull complete
5e5679988195: Pull complete
799abad6ce99: Pull complete
384fcf967d83: Pull complete
dc6d19da5f5f: Pull complete
Digest: sha256:14d97a040222d434a31e6db5706c9117ba2c006fb427e1e561e4d3650bf066d3
Status: Downloaded newer image for microsoft/dotnet-samples:aspnetapp
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
No XML encryptor configured. Key {adfb2c92-2470-4fdc-964f-a42444bcf844} may be persisted to storage in unencrypted form.
Hosting environment: Production
Content root path: /app
Now listening on: http://[::]:80
Application started. Press Ctrl+C to shut down.

Opened my browser to http://0.0.0.0:8000 and there it was!

I was actually shocked that it worked that easily. If this actually worked on my Mac, then I don’t see any reason why this wouldn’t in fact run on DC/OS. This is in fact all the magic through the Docker Engine. That is all that is really needed.

Before going any further, I feel like I need to show this again.

Disclaimer: I am in no way shape or form a .NET developer, have any sort of experience running .NET apps nor am I advocating that you run .NET apps. But I am also not saying that you shouldn’t run .NET apps.

I went to the drawing board and crafted the following Marathon JSON to test a true deployment for a “real world” type of scenario:

{
"labels": {
"HAPROXY_GROUP": "external"
},
"id": "/dotnet",
"backoffFactor": 1.15,
"backoffSeconds": 1,
"container": {
"portMappings": [
{
"containerPort": 80,
"hostPort": 0,
"labels": {
"VIP_0": "/dotnet:8000"
},
"protocol": "tcp",
"servicePort": 10101,
"name": "dotnet"
},
{
"containerPort": 0,
"hostPort": 0,
"protocol": "tcp",
"servicePort": 10104
}
],
"type": "DOCKER",
"volumes": [],
"docker": {
"image": "microsoft/dotnet-samples:aspnetapp",
"forcePullImage": false,
"privileged": false,
"parameters": []
}
},
"cpus": 0.5,
"disk": 0,
"healthChecks": [
{
"gracePeriodSeconds": 300,
"intervalSeconds": 60,
"maxConsecutiveFailures": 3,
"portIndex": 0,
"timeoutSeconds": 20,
"delaySeconds": 15,
"protocol": "MESOS_HTTP",
"path": "/",
"ipProtocol": "IPv4"
}
],
"instances": 1,
"maxLaunchDelaySeconds": 3600,
"mem": 128,
"gpus": 0,
"networks": [
{
"mode": "container/bridge"
}
],
"requirePorts": false,
"upgradeStrategy": {
"maximumOverCapacity": 1,
"minimumHealthCapacity": 1
},
"killSelection": "YOUNGEST_FIRST",
"unreachableStrategy": {
"inactiveAfterSeconds": 0,
"expungeAfterSeconds": 0
},
"fetch": [],
"constraints": []
}

The following JSON definition includes things such as:

  • A Label and ServicePort for Marathon LB (“HAPROXY_GROUP”: “external” and “servicePort”: 10101,) so users can reach this statically from outside the cluster.
  • A VIP address so that other services can interact with the service in a static manner (“portMappings”).
  • Health Checks so that Marathon can successfully orchestrate the service if the service becomes unhealthy. See “healthChecks” key in the JSON.

Let’s deploy it using DC/OS CLI!

dcos marathon app add dotnet.json

I can now access the app through my Public Agent running my Marathon LB app!

How about scaling? Yep!

dcos marathon app update dotnet instances=5

Once again I can hit the .NET default UI! And, I only spent about a total of 15 minutes getting to this point. Cool!

Even though this is not a real app and there are no real plans of actually running .NET apps in our environment, you can see how simple this reality could become. Within a very short amount of time I was able to get a fully functioning and scalable .NET app running on DC/OS. This could potentially lead us to a scenario where we could provide users with the ability if we desire. Again…

Disclaimer: I am in no way shape or form a .NET developer, have any sort of experience running .NET apps nor am I advocating that you run .NET apps. But I am also not saying that you shouldn’t run .NET apps.

…not saying that you should or should not do this. I remain open minded and advocate for tech that makes sense in every unique scenario. I am simply providing and demonstrating the ability to provide users with more flexibility for more services (FILL IN THE BLANK-as-a-Service). This is what its all about for me.

I had a few people interested in this so I wrote this short article. I originally wrote it for Marathon but if there is more interest in an example of running on Kubernetes, please see the Github link (which is also supported orchestrator on DC/OS).

--

--

Husband. Father. Friend. Mentor. Developer. Engineer. | Sr MLOps Eng