<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Scott Rangeley on Medium]]></title>
        <description><![CDATA[Stories by Scott Rangeley on Medium]]></description>
        <link>https://medium.com/@scott.rangeley?source=rss-6d9b41d016c2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*xhaeJVX99yZFHFbDBBXHhg.jpeg</url>
            <title>Stories by Scott Rangeley on Medium</title>
            <link>https://medium.com/@scott.rangeley?source=rss-6d9b41d016c2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 13:05:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@scott.rangeley/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Create And Provision Your Local VM With Vagrant, Hyper-V and Docker-Machine]]></title>
            <link>https://medium.com/@scott.rangeley/create-and-provision-your-local-vm-with-vagrant-hyper-v-and-docker-machine-d1acf0571256?source=rss-6d9b41d016c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1acf0571256</guid>
            <category><![CDATA[hyper-v]]></category>
            <category><![CDATA[virtual-machine]]></category>
            <category><![CDATA[vagrant]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Scott Rangeley]]></dc:creator>
            <pubDate>Fri, 26 Jan 2018 16:03:36 GMT</pubDate>
            <atom:updated>2018-01-26T16:03:36.882Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve lately been in a situation where I wanted to create a Linux virtual machine for local environments, using Hyper-V to host a handful of containers. The kicker being that I had some PowerShell script to deploy these containers. I tried using docker-machine, but the Linux distribution that Boot2Docker uses, or is based from (called <a href="http://tinycorelinux.net/">Tiny Core Linux</a>), doesn’t seem to have a way to install PowerShell + .NET Core (if it does, maybe someone can enlighten me!). The core of this post is to document what I did in order to work around this — maybe one of you guys have come across this. If you have, and got some value from it, great!</p><h3>Vagrant Basics</h3><p>Before we start anything, lets create an external virtual switch in Hyper-V Manager (unless you have one already).</p><pre>Actions <br>→ Virtual Switch Manager <br>→ Select External <br>→ Create Virtual Switch <br>→ Name: {Give your virtual switch a name!} <br>→ Apply</pre><p>So I am going to be using this <a href="https://app.vagrantup.com/generic/boxes/ubuntu1704">Vagrant box</a>, since this was the more up to date and active one I found. I’ve navigated to</p><pre>D:\Virtual\Ubuntu</pre><p>and run the following command against the Vagrant cli</p><pre>vagrant init generic/ubuntu1704</pre><p>This will create a “virtual machine template” that Vagrant can use to build your virtual machine. If you’re too curious, and want to boot up your virtual machine now, run this in a command line run as <strong>Administrator.</strong> You’ll be prompted with what switch to use, select the one you created through Hyper-V Manager earlier.</p><pre>vagrant up --provider hyperv</pre><p>this will boot it up for you (notice that I am specifying the provider, which is Hyper-V in our case, by default Vagrant uses VirtualBox). Awesome, but you’ll obviously want to install some stuff on it automatically. To tear down this machine, either shut down and delete from your Hyper-V manager console, or simply run this in the same folder</p><pre>vagrant destroy</pre><p>Sweet, managed to get pretty much every command you’ll most likely need to use in regards to Vagrant over in the first section! There’s one more, but I won’t ruin the surprise this early on.</p><h3>Provisioning Your Machine</h3><p>So we have our virtual machine, but we need a few bits installed in order to run our PowerShell script within it… namely PowerShell, and .NET Core. Lets venture into what we have in our Vagrantfile that the ‘vagrant init’ command created.</p><pre>Vagrant.configure(&quot;2&quot;) do |config|<br>  config.vm.box = &quot;generic/ubuntu1704&quot;<br>end</pre><p>Not too much here, pretty much just saying that this is my template you should deploy.</p><p>First of all, lets specify our provider in our config , so we don’t have to specify it in our ‘vagrant up’ command every time. We will also specify some other Hyper-V configuration here. Add this new section, so your Vagrantfile looks like this</p><pre>Vagrant.configure(&quot;2&quot;) do |config|<br>  config.vm.box = &quot;generic/ubuntu1704&quot;<br>  config.vm.provider :hyperv do |hyperv|<br>    hyperv.vmname = &quot;UbuntuVirtualMachine&quot;<br>  end<br>end</pre><p>Next, lets remove that annoying prompt, which asks you what switch to use — this should be automated! Add the following line after our ‘vm.provider’ configuration section…</p><pre>config.vm.network &quot;public_network&quot;, bridge: &quot;{YOUR_V_SWITCH_NAME}&quot;</pre><p>Now you should be able to deploy your virtual machine, with a name, and not be prompted with what switch to use! Lets progress onto installing PowerShell and .NET Core.</p><p>We will use the “shell” option to provision, so we can just write a simple bash script which will be executed on the virtual machine. Create a new file in that same folder named “init.sh”. This is all pretty self explanatory, so here’s the script just for reference.</p><pre># PowerShell<br>wget --progress=bar:force <a href="https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-beta.4/powershell_6.0.0-beta.4-1ubuntu1.16.04.1_amd64.deb">https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-beta.4/powershell_6.0.0-beta.4-1ubuntu1.16.04.1_amd64.deb</a><br>sudo apt install ./powershell_*.deb -y<br></pre><pre># .NET Core<br>curl <a href="https://packages.microsoft.com/keys/microsoft.asc">https://packages.microsoft.com/keys/microsoft.asc</a> | gpg --dearmor &gt; microsoft.gpg<br>sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg<br>sudo sh -c &#39;echo &quot;deb [arch=amd64] <a href="https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod">https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod</a> xenial main&quot; &gt; /etc/apt/sources.list.d/dotnetdev.list&#39;<br>sudo apt-get update<br>sudo apt-get install dotnet-sdk-2.0.0 -y</pre><p>Lets alter our Vagrantfile to actually use this script in the virtual machine, add this line to do so</p><pre>config.vm.provision &quot;shell&quot;, path: &quot;init.sh&quot;</pre><p>I re-run the deployment and checked the version of both of these, and both seemed to be installed</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/353/1*TAufNwWucne9cDHhiLNjRA.png" /><figcaption>Verifying PowerShell and .NET Core was installed.</figcaption></figure><h3>Docker-Machine</h3><p>The next goal is to hook up our virtual machine, so we can see and access it via docker-machine. For this, we’re going to do some ssh setup, so docker-machine can access it and install docker. For this, we’re going to use vagrants default insecure key. Add this ssh configuration to your vagrant file</p><pre>config.ssh.insert_key = false</pre><p>Once done, we can tell docker-machine to use the default insecure key, which is located…</p><pre>C:/Users/${Username}/.vagrant.d/insecure_private_key</pre><p>So now, if you redeploy your vagrant file with the ssh changes, we can run this docker-machine command to kick off the provisioning of docker on that vm. Amend the following command to accommodate for new lines.</p><pre>docker-machine create <br>    --driver generic <br>    --generic-ssh-user vagrant <br>    --generic-ssh-key ${PathToInsecureKeyMentionedAbove} <br>    --generic-ip-address ${VMIpAdress} <br>    UbuntuVM</pre><p>Once that’s completed, you should be able to run…</p><pre>docker-machine ls </pre><p>and see your now docker provisioned vm!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*XhpswHS8yZavs1HlFIf8iQ.png" /></figure><p>We can now ssh via docker-machine and start doing docker things.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1015/1*1SNWcKSBBbEhQCAxLivbew.png" /></figure><p>Ideally, you’d want to automate all of this using PowerShell, and that’s what I ended up doing. By doing that you could also cluster the virtual machines using Docker Swarm, which also could be a fun continuation from this post :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1acf0571256" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From The Ground Up: Basics Of Porting To Orleans 2.0 Beta]]></title>
            <link>https://medium.com/@scott.rangeley/from-the-ground-up-basics-of-porting-to-orleans-2-0-beta-af6824990d77?source=rss-6d9b41d016c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/af6824990d77</guid>
            <category><![CDATA[microsoft-orleans]]></category>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[microsoft-orleans-2-beta]]></category>
            <category><![CDATA[microsoft]]></category>
            <category><![CDATA[distributed-dotnet-core]]></category>
            <dc:creator><![CDATA[Scott Rangeley]]></dc:creator>
            <pubDate>Thu, 23 Nov 2017 13:52:01 GMT</pubDate>
            <atom:updated>2017-11-23T13:52:01.809Z</atom:updated>
            <content:encoded><![CDATA[<h3>What Will I Cover Here?</h3><p>Orleans 2.0 has finally been published to <em>nuget.org</em> as their beta release which makes Orleans .NET Core compatible <a href="https://github.com/dotnet/orleans/releases/tag/v2.0.0-beta1">(see their release notes here!).</a> I’ve recently been working towards porting over an existing Orleans project from Orleans 1.5 to 2.0, and thought I’d share the sort of changes required to make. The goal here is to showcase how easy it is to get going with Orleans 2.0 now with their new changes. I’m seriously impressed with how easy it is, and will hopefully open the door to more people wanting to write scalable, distributed applications in .NET.</p><p>I am making the assumption that you’re familiar with Orleans here — and will not proceed to completely explain the fundamentals of Orleans.</p><h3>Creating A Base To Work From</h3><p>I wanted to create the base of our application using the dotnet cli<em> </em>and vs code, so you can follow along if you’re using an environment other than Windows (I’m not deliberately being awkward, I promise!) — I am using <em>cmder</em> to run these commands, so the “&amp;” to link commands might not work on what environment you’re using, change accordingly!</p><p>So let’s create the solution, and add a console application as our entry point — this will be our silo. Here we’re creating a new folder, and a new solution within that folder. A new console application template will be created, and added to that solution we’ve created.</p><pre>mkdir Orleans2Template &amp;<br>cd Orleans2Template &amp;<br>dotnet new sln &amp;<br>dotnet new console -o Silo --framework netcoreapp2.0 &amp;<br>dotnet sln add Silo\Silo.csproj</pre><p>We will then create our class library grain interface project, add it to the solution, and have our silo project reference it.</p><pre>dotnet new classlib -o GrainInterfaces --framework netstandard2.0 &amp;</pre><pre>dotnet sln add GrainInterfaces/GrainInterfaces.csproj &amp;</pre><pre>dotnet add Silo/Silo.csproj reference GrainInterfaces/GrainInterfaces.csproj</pre><p>Likewise for the grain interface project, we now create our implementation project</p><pre>dotnet new classlib -o GrainImplementations --framework netstandard2.0 &amp;</pre><pre>dotnet sln add GrainImplementations/GrainImplementations.csproj &amp;</pre><pre>dotnet add Silo/Silo.csproj reference GrainImplementations/GrainImplementations.csproj</pre><p>Lets now reference our <em>GrainInterfaces</em> project within our <em>GrainImplementation</em> project…</p><pre>dotnet add GrainImplementations/GrainImplementations.csproj reference GrainInterfaces/GrainInterfaces.csproj</pre><p>We can then start adding NuGet package references to all the projects…</p><pre>dotnet add Silo/Silo.csproj package Microsoft.Orleans.Core --version 2.0.0-beta1 &amp;</pre><pre>dotnet add Silo/Silo.csproj package Microsoft.Orleans.OrleansProviders --version 2.0.0-beta1 &amp;</pre><pre>dotnet add Silo/Silo.csproj package Microsoft.Orleans.OrleansRuntime --version 2.0.0-beta1 &amp;</pre><pre>dotnet add Silo/Silo.csproj package Microsoft.Extensions.Logging.Console --version 2.0.0 &amp;</pre><pre>dotnet add GrainImplementations/GrainImplementations.csproj package Microsoft.Orleans.Core --version 2.0.0-beta1 &amp;</pre><pre>dotnet add GrainInterfaces/GrainInterfaces.csproj package Microsoft.Orleans.Core --version 2.0.0-beta1 &amp;</pre><pre>dotnet restore</pre><h3>Cleaner Silo Initialisation</h3><p>First of all, Orleans 2.0 has introduced a cleaner way of initialising your silo, which is akin to how ASP.Net Core does — similar to the <em>WebHostBuilder.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b9500e8132bacb69d9b82f580ad48082/href">https://medium.com/media/b9500e8132bacb69d9b82f580ad48082/href</a></iframe><p>This is obviously the bare minimum setup, but you can see we have the <em>SiloHostBuilder</em> to construct our silo which looks infinitely much cleaner than the custom initialisation logic, or the <a href="https://github.com/OrleansContrib/OrleansTemplates/blob/master/VSTemplates/ETG.Orleans.Templates.Host/OrleansHostWrapper.cs"><em>OrleansHostWrapper</em></a> class which existed before. We can extend our silo with more features using the builder, but for now we will use the bare minimum, and add some fancy stuff later.</p><h3>Cleaner Grain Client Initialisation</h3><p>Similar to the <em>SiloHostBuilder</em>, our grain clients received the love too — in the form of the <em>ClientBuilder. </em>If you you’ve adopted Orleans earlier on, you’re potentially still using the static GrainClient. The static GrainClient will be dropped in favour of this non static approach — enabling silos to construct grain clients which point to other silos (from a silo), which is pretty sweet.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f2bb948729a717c8772c24e28cff0d7/href">https://medium.com/media/2f2bb948729a717c8772c24e28cff0d7/href</a></iframe><p>Let’s add a method in <em>Program.cs</em> to build a grain client, and invoke a grain within our silo — here’s a snippet of what the construction of a grain client would be <em>(I’ve deliberately emitted retry logic for the sake of clarity, that’s something you’d probably want to implement)</em></p><p>So clean!</p><h3>Code Generation &amp; Assembly Loading</h3><p>So lets continue on with our template — lets add a HelloGrain which takes a parameter and prints a greeting to the name in that string. I won’t go through all this as it all pretty much remains the same. I am now going to invoke that <em>HelloGrain </em>from <em>Program.cs </em>like so</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b4e8e6a32c2f6e3eaff1343e859a28f/href">https://medium.com/media/3b4e8e6a32c2f6e3eaff1343e859a28f/href</a></iframe><p>If you now try running this, you might get something along the lines of…</p><pre>Make sure the grain assembly was correctly deployed and loaded in the silo.</pre><p>There’s two gotcha’s with Orleans 2 that is now required. One of them is referencing the <em>OrleansCodeGenerator.Build</em> NuGet package for your interface and implementation projects. The run time code generation is now not used in Orleans 2, with build time code generation being favoured instead. Lets add these references</p><pre>dotnet add GrainInterfaces/GrainInterfaces.csproj package Microsoft.Orleans.OrleansCodeGenerator.Build --version 2.0.0-beta1 &amp;<br> <br>dotnet add GrainImplementations/GrainImplementations.csproj package Microsoft.Orleans.OrleansCodeGenerator.Build --version 2.0.0-beta1 &amp;</pre><pre>dotnet restore</pre><p>Sweet — the second gotcha is that you now have to specify what assemblies the silo and grain client have to load — this is done in the builder for both silo and client. You essentially just call an extension method to load assemblies for a grain within a particular assembly (So one grain in each assembly requires this!)</p><pre>.AddApplicationPartsFromReferences(typeof(HelloGrain).Assembly)</pre><p>This was previously “blind scanning” all of the assemblies that was loaded in by the <em>AppDomain </em>by default — this alongside various other improvements to build time code generation has made a noticeable difference for silo deployment times, which is always great news.</p><h3>Logging (MEL Integration)</h3><p>I’m a big big fan of the changes made to logging — if you’ve used logging in ASP.NET Core, you’ll be familiar with Orleans, since it’s using the same abstractions and interfaces. Lets recap on what we’ve done previously, in our client and silo builders. We specified this line in our builder</p><pre>.ConfigureLogging(logging =&gt; logging.AddConsole())</pre><p>Pretty self explanatory — but how do we use it? Exactly how you would in ASP.NET Core, with dependency injection, but injecting into our Grain opposed to a Controller. In my <em>HelloGrain</em>, I’ll just do the following to add the ability to use this logger.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5bdde4a36e681cd93b13cf8374b561bd/href">https://medium.com/media/5bdde4a36e681cd93b13cf8374b561bd/href</a></iframe><p>So here we can see the greeting from my grain code, and my log</p><pre>Hello, Scott Rangeley<br>info: GrainImplementations.HelloGrain[0]<br>    SayHello has been invoked!</pre><h3>Configuration — No ConfigurationManager!</h3><p>Probably not a direct Orleans change, but something that will be needed when porting over to .NET Core — no more <em>ConfigurationManager </em>means that we now have to use an <em>IConfiguration </em>object, which can be injected into grains similar to the <em>ILogger </em>interface. Lets add a configuration file, I’ll call it <em>appSettings.json</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b257a821d0fbd101d42f43da1d614824/href">https://medium.com/media/b257a821d0fbd101d42f43da1d614824/href</a></iframe><p>So here we’re going to make our greeting configurable, which will be used by our <em>HelloGrain</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3fb5168ce9ddf0562065de036e26f9d/href">https://medium.com/media/f3fb5168ce9ddf0562065de036e26f9d/href</a></iframe><p>Now to get that configuration into a object we can inject, let’s build it from our json file— you will need extra references to use these extension methods</p><p>Run this to add these required NuGet packages</p><pre>dotnet add Silo/Silo.csproj package Microsoft.Extensions.Configuration.FileExtensions --version 2.0.0 &amp;</pre><pre>dotnet add Silo/Silo.csproj package Microsoft.Extensions.Configuration.Json --version 2.0.0 &amp;</pre><pre>dotnet restore</pre><p>We will now amend our silo builder to add our <em>IConfiguration</em> object into our service collection, which can be injected into our grains.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f0e609de2ea58843d29a6a4baa1d3325/href">https://medium.com/media/f0e609de2ea58843d29a6a4baa1d3325/href</a></iframe><p>…now we can; similar to our <em>ILogger </em>object already being injected into the grain, inject an <em>IConfiguration </em>object and use that — here’s how my grain method now looks</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f8f994f5398859922ce7439a45e2c637/href">https://medium.com/media/f8f994f5398859922ce7439a45e2c637/href</a></iframe><h3>Finishing Up</h3><p>I obviously haven’t covered all the great work the guys working on Orleans have done, but hopefully I’ve covered enough for you to get going with it. It’s exciting times for Orleans at the moment, with how easy it’s to write fully scalable, distributed application in Orleans; .NET Core compatibility makes things such as Docker integrations nicer and more simple!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/0*RIYq4tlYVZZRQf2j.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af6824990d77" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker Swarm Container Reconciliation Is Amazing]]></title>
            <link>https://medium.com/@scott.rangeley/docker-swarm-container-reconciliation-is-amazing-31fa03947b55?source=rss-6d9b41d016c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/31fa03947b55</guid>
            <category><![CDATA[swarm]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[orleans]]></category>
            <category><![CDATA[microsoft-orleans]]></category>
            <dc:creator><![CDATA[Scott Rangeley]]></dc:creator>
            <pubDate>Fri, 06 Oct 2017 12:18:23 GMT</pubDate>
            <atom:updated>2017-10-07T08:53:51.648Z</atom:updated>
            <content:encoded><![CDATA[<p>As I progress into porting my Orleans cluster to use Orleans 2.0 (thus .NET Core 2.0) giving me easier Docker support, I’m continued to be impressed with how awesome Docker actually is. I was really impressed by how Docker automatically initiates reconciliation of containers when nodes in your swarm cluster are dropped. I wanted to further dive into experimenting with this, and maybe explain a little of what is actually happening.</p><h3>The Setup</h3><p>Similar to my previous post, I’ll be creating a swarm cluster of four nodes; one manager and three worker nodes. The cluster will have a docker registry service which will allow me to deploy my own application/docker image across all swarm nodes. A <strong>single </strong>ZooKeeper service for Orleans silo cluster membership, and <strong>twelve </strong>Orleans silos.</p><p>For reference on how I set all of this up, take a look at <a href="https://medium.com/@scott.rangeley/simply-put-deploying-microsoft-orleans-to-docker-swarm-d21d4f16cbc6">my previous post</a>, it will guide you through how I set all of this up.</p><h3>Why And What Container Reconciliation Is</h3><p>Say we have <em>five</em> nodes in our swarm cluster hosting <em>ten</em> containers. One of those nodes happen to fail, taking down <em>three </em>containers on that node — what happens? Swarm will notice that we’re missing three containers, and automatically schedule them across whatever machines are available in the cluster. What happens if my container fails due to some dependency on a container that failed or hasn’t started yet, or because of the container being unhealthy? Swarm will kill that container and reschedule it again.</p><p>How does it do this magic though? It’s achieved through “desired vs. actual state” reconciliation. I was watching a video on <em>Kubernetes </em>the other day, presented by Brendan Burns (I know, it’s a different technology, but uses a similar solution to swarm) — you can see the snippet from <a href="https://youtu.be/WwBdNXt6wO4?t=14m47s">here</a>. His analogy describes this form of reconciliation similar to a thermostat. The thermostat will take a recording of the <strong>actual </strong>temperature in the room, and then compare that against our <strong>desired </strong>temperature we set the thermostat to. If there’s a difference between the two, action will be taken in order to make our actual state resemble our desired — in some case, heat up the room if our actual state is colder than what we set.</p><p>This is pretty much the same with containers, our desired state would be whatever services we’ve said we want deployed to our cluster, and our actual state is well, what we have at that point in time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*FUlPPP3-eOsURbpTi2ujqg.png" /></figure><h3>How Are These States Maintained?</h3><p>As already mentioned previously, you can have two types of nodes within a swarm cluster — manager and worker nodes. The manager node maintains the desired state, and actual state of swarm (there are other things, but will not digress). Obviously having a single manager node introduces a single point of failure. To avoid this, you can create multiple manager nodes. These states are kept consistent between all manager nodes, by using the Raft consensus algorithm (if you’re unfamiliar with the Raft algorithm, <a href="http://thesecretlivesofdata.com/raft/">check this out, it’s an amazing explanation on Raft</a>). It’s important to note, even with multiple manager nodes, there’s only one true leader, who makes all the decisions. If that leader manager node happens to fail, another manager is elected as the new leader. The clusters state is already available thanks to the consistent state maintained between all managers, meaning that the new leader can start making decisions.</p><h3>Lets Destroy Things</h3><p>I can explain, give links to other blogs &amp; websites, but I always find it better to see it all in action, so lets do exactly that. Lets start a swarm cluster, deploy some containers to it and destroy machines/containers. So I have swarm running here, with <em>one </em>ZooKeeper container, and <em>twelve </em>silo containers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*3b4YEhpIAkCA67PWyF2Fhw.png" /></figure><p>So lets run</p><pre><strong>docker stack</strong> ps <strong>-f &quot;</strong>desired-state=running&quot; toasterservice</pre><p>to see what silos are running on what machines.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*r_lV3R9tq3v98xQiA-elDA.png" /></figure><p>For this, lets kill the node1 virtual machine, let’s just check what silos are running on that node by running</p><pre><strong>docker stack</strong> ps <strong>-f</strong> &quot;desired-state=running&quot; <strong>-f</strong> &quot;node=node1&quot; toasterservice</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*_QoWiRc2kJlEBGMawe0PqQ.png" /></figure><p>so these silos will inevitably die along with the virtual machine falling… Lets now kill the virtual machine</p><pre>docker-machine stop node1</pre><p>Now, we would expect swarm to notice that these three containers are missing, and move those three silos (silo.1, silo.2 and silo.8) onto another machine. Let’s check this by running this command again, to get currently running containers.</p><pre><strong>docker stack</strong> ps <strong>-f &quot;</strong>desired-state=running&quot; toasterservice</pre><p>That is exactly what happened.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*fzBVp69GkIAWww5a_3fIwA.png" /></figure><p>Pretty damn cool.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31fa03947b55" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simply Put: Deploying Microsoft Orleans To Docker Swarm]]></title>
            <link>https://medium.com/@scott.rangeley/simply-put-deploying-microsoft-orleans-to-docker-swarm-d21d4f16cbc6?source=rss-6d9b41d016c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/d21d4f16cbc6</guid>
            <category><![CDATA[orleans]]></category>
            <category><![CDATA[zookeeper]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[microsoft-orleans]]></category>
            <category><![CDATA[swarm]]></category>
            <dc:creator><![CDATA[Scott Rangeley]]></dc:creator>
            <pubDate>Fri, 29 Sep 2017 14:39:50 GMT</pubDate>
            <atom:updated>2017-10-01T10:57:44.118Z</atom:updated>
            <content:encoded><![CDATA[<p>Docker is something that I just can’t get enough of, it’s taken up all my time since seeing how easy it was to deploy third party dependencies such as RabbitMQ <em>(yes, I am lazy, I hate installing things!)</em>. I eventually progressed onto moving my own applications into containers. This was incredibly fun, being able to run an application, with external dependencies in one command? madness. Naturally, the next step would be to move to something more distributed, with <a href="https://dotnet.github.io/orleans/">Microsoft Orleans</a> being my first choice.</p><p>So what are we going do attempt to do here? this is what I am aiming to explain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*c-PK-6wYzrnIBgYjaPdtYA.png" /></figure><p>So how are we going to do this? we’re going to do a few things — create a swarm cluster of 4 nodes, define our docker-compose file, and triggering that deployment against those nodes in the swarm cluster.</p><h3>Creating A Swarm Cluster Locally</h3><p>So the first step would be to create some virtual machines, to simulate a clustered environment. We’re going to be using Docker Machine to do this. Docker Machine is part of docker that allows you to create virtual machines with docker installed; It also provides tools to manage these virtual machines. For these examples, I’ll be using <em>Hyper-V</em>, and <em>cmd</em> for running all these commands, so please change accordingly to your environment. It will be worth following this <a href="https://docs.docker.com/machine/drivers/hyper-v/#2-set-up-a-new-external-network-switch-optional">guide on creating a virtual switch</a>, whenever I reference “dSwitch” in the following commands, it’s the name of the switch I created in Hyper-V!</p><p>Lets first create our manager node, this will schedule our services/containers across our other swarm nodes.</p><pre><strong>docker-machine</strong> create <strong>-d</strong> hyperv — <strong>hyperv-virtual-switch</strong> “dSwitch” managerNode</pre><p>Now lets verify that it got created and grab the IP address for that node by using</p><pre><strong>docker-machine</strong> ls</pre><p>Before we continue, lets point our shell to managerNode, so we can execute docker commands as if it were local, but actually executing on the managerNode VM. This can be done by running</p><pre><strong>docker-machine</strong> env managerNode</pre><p>Then copying the command from the output of that, and running it.</p><p>Now, using the IP address returned for our “managerNode” instance, we’re going to use that for our next command:</p><pre><strong>docker swarm</strong> init <strong>--advertise-addr</strong> {ip}</pre><p>This will initialise docker swarm, and make this a manager node, good job! Let’s now create other virtual machines, which are workers, that join part of the docker swarm cluster we’ve just created.</p><pre><strong>for</strong> /l %x <strong>in</strong> (1, 1, 3) <strong>do</strong> <strong>docker-machine</strong> create <strong>-d</strong> hyperv <strong>--hyperv-virtual-switch</strong> &quot;dSwitch&quot; node%x</pre><p>We’ve simply looped in cmd, running <em>docker-machine create</em> (with our defined switch), easy enough; lets now make these join the swarm cluster.</p><pre><strong>for</strong> /l %x <strong>in</strong> (1, 1, 3) <strong>do</strong> <strong>docker-machine</strong> ssh node%x &quot;<strong>docker</strong> swarm join <strong>--token</strong> {token} {managerNode ip}&quot;</pre><p><strong>It’s important to note, the token we’re passing here is what was returned when running docker swarm init on the managerNode!</strong></p><p>Let’s now check that all these nodes have been created and part of the swarm, run…</p><pre><strong>docker node</strong> ls</pre><h3>Orleans, Membership And ZooKeeper</h3><p>For this deployment, we need some way of maintaining a list of silos in our Orleans cluster. We will be using ZooKeeper here. If you’re a bit unsure on how membership works, there’s some great information in the <a href="https://dotnet.github.io/orleans/Documentation/Runtime-Implementation-Details/Cluster-Management.html">Orleans documentation</a>. Needless to say, ZooKeeper is a dependency on making this work, so let’s configure our silo to use this, and where it can reach it.</p><p>I’ll be using the amended <a href="https://github.com/creyke/ToasterService">ToasterService template</a> to achieve this, it can be found <a href="https://github.com/Scottlr/ToasterService">here</a>. The main change is how the silo is configured, you can see it here</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/51d04009230acfbed9172f7a0e2fa04a/href">https://medium.com/media/51d04009230acfbed9172f7a0e2fa04a/href</a></iframe><p>it’s clear that we’re saying that the <em>LivenessType</em> is ZooKeeper and that the endpoint to reach it is “zookeeper:2181”. The “zookeeper” endpoint will be resolved by docker.</p><h3>Prep For Deployment</h3><p>Before we can start the fun part; deploying, we need to do some work to allow all the swarm nodes know were to get our ToasterService docker image from. To do this, we’re going publish our application, build our image, create a registry and push our image to that registry.</p><p>Firstly, let’s publish our application, so docker knows what to copy into the container (what we’re copying is defined in our Dockerfile)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*oxESrG9Ggm4B8_jl2C3MTA.png" /></figure><p>The above image should give enough information on how to do this! Once your application has been published, run the following command to build the image.</p><pre><strong>docker-compose</strong> build</pre><p>Now we have our image, we need to publish it to a registry. This registry needs to be available to all nodes in swarm — meaning we have to host a registry within our swarm cluster — lets create this registry by running</p><pre><strong>docker service</strong> create <strong>--name</strong> registry <strong>--publish</strong> 5000:5000 registry</pre><p>Now lets tag our toasterservice image we just built so we can push it to our registry.</p><pre><strong>docker tag</strong> toasterservice localhost:5000/toasterservice</pre><p>Followed by this command to actually push it to the registry</p><pre><strong>docker push</strong> localhost:5000/toasterservice</pre><h3>Lets Start Deploying!</h3><p>So we have our Orleans silo configured to allow for clustered deployment (through membership with ZooKeeper), and we have our docker swarm set up, waiting for work. First off, let’s start defining our <em>docker-compose.yml</em> file, so we know what we’re deploying.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d3426cb59299b78c212ff55a875d54e3/href">https://medium.com/media/d3426cb59299b78c212ff55a875d54e3/href</a></iframe><p>The main differences here from the existing compose file is that the image is pointing to our registry we deployed to swarm. We’re also saying that we want 5 replicas of our toasterservice container — a cluster of 5 silos! <em>I call this docker-stack just to differentiate between compose and stack deployments.</em></p><p>Sweet, so we’re good to go, let’s kick this deployment off with the following command</p><pre><strong>docker stack</strong> deploy <strong>-c</strong> docker-stack.yml toasterservice</pre><p>Here we’re going to be using our <em>docker-stack.yml</em> file, which will deploy all services defined, under the name “toasterservice” — that’s it, your service is now deployed! But, how can we check that it successfully deployed and that I am not just lying to you? Let’s run a command to check the state of our toasterservice deployment…</p><pre><strong>docker stack</strong> ps toasterservice</pre><p>This will list all containers under this deployment, including failed containers. If you do have a failed container, it will most likely be due to the fact that ZooKeeper might not of been available at the time the silo started. In this scenario, the container will be redeployed a few more times in an attempt to reconcile our “desired state” we defined in our compose file (5 replicas).</p><h3><strong>Bonus</strong>: Lets Prove It’s Actually Clustered…</h3><p>I mean, I could easily deploy all of this and say that this is a valid Orleans cluster, when it isn’t — but lets prove it. How? we will kill a silo, and see if our other silos notices this and marks it as dead…</p><p>Let’s choose our victim… I’ll get all running nodes and choose which silo to kill</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*PFBl5WZ4YhJnSat6b1IEMA.png" /></figure><p>I like the look of<em> toasterservice.3</em>, which is sitting on swarm <em>node1. </em>Lets ssh into <em>node1 </em>and stop that container.</p><pre><strong>docker-machine</strong> ssh node1</pre><p>now we can run list all containers on node1, grab the ContainerId for toasterservice.3</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AmM-DnHOnJo3So0cH21Hdg.png" /></figure><p>If I inspect that container, I can grab the IP Address for it, for me the IP Address is “10.0.0.5”. Lets now kill it by stopping the container — by running</p><pre><strong>docker stop</strong> [ContainerId]</pre><p><em>(type exit to get out of node1)</em></p><p>Now, if I grep some of the logs on a silo, I can see that they voted for the silo with that IP address, to be marked as DEAD</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*dA8THaiVes4lounsRBNU4Q.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FZMyLicvZlX7OM%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FZMyLicvZlX7OM%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FZMyLicvZlX7OM%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="243" frameborder="0" scrolling="no"><a href="https://medium.com/media/0356e7a6b3dffd7385e8eee88cf9327d/href">https://medium.com/media/0356e7a6b3dffd7385e8eee88cf9327d/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d21d4f16cbc6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>