<?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 Ivan Mikushin on Medium]]></title>
        <description><![CDATA[Stories by Ivan Mikushin on Medium]]></description>
        <link>https://medium.com/@imikushin?source=rss-8307b6d58a37------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*U77b-_0yxhlkFUa_5FjCaA.jpeg</url>
            <title>Stories by Ivan Mikushin on Medium</title>
            <link>https://medium.com/@imikushin?source=rss-8307b6d58a37------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 22:43:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@imikushin/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[Istio metrics with StatsD]]></title>
            <link>https://medium.com/@imikushin/istio-metrics-with-statsd-278165127a0?source=rss-8307b6d58a37------2</link>
            <guid isPermaLink="false">https://medium.com/p/278165127a0</guid>
            <category><![CDATA[istio]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[statsd]]></category>
            <dc:creator><![CDATA[Ivan Mikushin]]></dc:creator>
            <pubDate>Sat, 22 Dec 2018 18:11:37 GMT</pubDate>
            <atom:updated>2018-12-22T18:11:37.260Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K8xBZ_7MBGFwGRji7hULAw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/NA0JoQF-8q8?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Hubert Mousseigne</a> on <a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Something had stung me: I decided (for undisclosed reasons) I needed to report metrics from <a href="https://istio.io/">Istio</a> with <a href="https://github.com/etsy/statsd">StatsD</a> protocol. With everything running on a Kubernetes cluster (of course).</p><p>StatsD is a very <a href="https://github.com/b/statsd_spec">simple text based protocol</a> working over UDP. A StatsD metric report is a line of text looking like this:</p><pre>&lt;metric name&gt;:&lt;value&gt;|&lt;type&gt;</pre><p>You send that line over UDP and forget about it.</p><h3>UDP to stdout</h3><p>I needed a debug UDP server to see if the metrics were actually sent. Here’s what I’ve got after a few iterations:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/64076afdafa8d8331cbcbc8a211a4777/href">https://medium.com/media/64076afdafa8d8331cbcbc8a211a4777/href</a></iframe><p>That’s the Dockerfile I’ve used to build the server:</p><pre>docker build -t imikushin/statsd-stdout:2 .<br>docker push imikushin/statsd-stdout:2</pre><p>Then I needed to deploy it on my Kubernetes cluster. For that I needed just a little bit of YAML:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ade685391140b7ff179be10ad2d917ed/href">https://medium.com/media/ade685391140b7ff179be10ad2d917ed/href</a></iframe><p>Deploy it:</p><pre>kubectl apply -f <strong>statsd-stdout.yaml</strong></pre><p>Now you can send UDP traffic to <br>statsd-stdout.default.svc.cluster.local:8125</p><p>And you can see what arrives there with this command:</p><pre>kubectl logs -f statsd-stdout</pre><p>It will print out whatever arrives via UDP on port 8125 which happens to be the StatsD protocol UDP port.</p><p>Let’s test it out before sending any StatsD traffic! Run this:</p><pre>kubectl run a1 -it --image=alpine sh</pre><p>Then, in the pod’s shell prompt:</p><pre>apk add -U socat</pre><pre>echo -n &quot;hello&quot; | socat - \<br>  udp4-sendto:statsd-stdout.default.svc.cluster.local:8125</pre><p>hello should appear in the statsd-stdout pod logs.</p><h3>Istio metrics and the StatsD adapter</h3><p>Figuring out how the heck metrics actually work in Istio took me a lot of time…</p><p>This is the result of tinkering and meditating over Istio docs. Here’s my working configuration to report request count to a service:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc379026b817694c7b29c2deb7464fcc/href">https://medium.com/media/dc379026b817694c7b29c2deb7464fcc/href</a></iframe><p>Although there’s only 2 YAML entities in this file, we’re actually talking about 3 things here:</p><ul><li>a metric: requestcount.metric.istio-system,</li><li>a telemetry adapter: revhandler.statsd.istio-system,</li><li>a rule: revstatsd.rule.istio-system</li></ul><p>A few interesting bits in this configuration:</p><ul><li>The match value of the rule: destination.service.host is the attribute containing in-cluster hostname of the request destination service. Our service is named helloworld-go-00001-service and it is in the default namespace.</li><li>address in the statsd adapter config is our StatsD UDP server address:<br>statsd-stdout.default.svc.cluster.local:8125</li><li>Keys under metrics in the statsd adapter config must be fully qualified names of metrics requestcount.metric.istio-system is already defined for us at Istio installation time. We can get its full definition by this command:<br>kubectl -n istio-system get metric requestcount -o yaml</li><li>nameTemplate value under the metric is a Go template: expressions in the form of {{.&lt;metric_dimension&gt;}} are replaced with the actual values from metric instances. For the set of dimensions, look at the metric definition:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/03b1b05a32fbf9eede2fcfccd0c2a262/href">https://medium.com/media/03b1b05a32fbf9eede2fcfccd0c2a262/href</a></iframe><p>If you apply the metrics config (with kubectl apply -f <strong>metrics.yaml</strong>), here’s what you’ll see in statsd-stdout logs (if any requests are made to helloworld-go-00001-service in the default namespace, of course):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f815e3576463cca5b1104c1850dc5dea/href">https://medium.com/media/f815e3576463cca5b1104c1850dc5dea/href</a></iframe><p>In this case we see requests made to our service by istio-ingressgateway. For each request, we see the counter increment reported.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=278165127a0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Adding a Language to Dispatch]]></title>
            <link>https://medium.com/dispatchframework/adding-a-language-to-dispatch-3515cce08e9f?source=rss-8307b6d58a37------2</link>
            <guid isPermaLink="false">https://medium.com/p/3515cce08e9f</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[clojure]]></category>
            <category><![CDATA[jvm]]></category>
            <dc:creator><![CDATA[Ivan Mikushin]]></dc:creator>
            <pubDate>Fri, 27 Apr 2018 18:59:02 GMT</pubDate>
            <atom:updated>2018-04-27T18:59:02.922Z</atom:updated>
            <content:encoded><![CDATA[<p>As of a couple weeks ago, you can run functions in <a href="https://vmware.github.io/dispatch/documentation/specs/language-support">ANY programming language</a> on Dispatch. To start, you need a <em>base image</em> for that language.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ThzkjOsGgkIW1hl2Z8sfdg.jpeg" /><figcaption>Build your FUNctions!</figcaption></figure><p>Dispatch already supports <a href="https://github.com/dispatchframework/nodejs-base-image">JavaScript</a>, <a href="https://github.com/dispatchframework/python3-base-image">Python 3</a>, <a href="https://github.com/dispatchframework/powershell-base-image">PowerShell</a>, <a href="https://github.com/dispatchframework/java-base-image">Java</a> and probably (by the time you’re reading this) others. I’m a big fan of <a href="https://clojure.org/">Clojure</a>, so I’ve created a <a href="https://github.com/dispatchframework/clojure-base-image">base image for it</a> to use as an example.</p><h3>Functions, Images, Base Images</h3><p>In Dispatch, <em>functions</em> are built on top of <em>images</em>, which themselves are built on top of <em>base images</em>. All of those are Docker images:</p><ul><li><em>Base image</em> provides the language runtime,</li><li><em>Image</em> provides library dependencies,</li><li><em>Function</em> wraps the function (source code) into a runtime API server, ready to execute incoming invocation requests</li></ul><p>We are building the <em>base image</em> for Clojure, which will contain templates for building images and functions. An overview of this process:</p><ol><li>Start with an empty Dockerfile</li><li>Choose the “FROM” image</li><li>Add language runtime and necessary system packages</li><li>Create image template</li><li>Create function template</li><li>Implement <a href="https://vmware.github.io/dispatch/documentation/specs/language-support#function-runtime-api">Function Runtime API</a></li><li>Write README</li></ol><h3>Choose the “FROM” image</h3><p>First, we need to choose the starting point, the “FROM” image. There are many great choices here (scratch, ubuntu, alpine, busybox, debian, vmware/photon2, etc.) depending on what your preferences for libc, package manager, package stability, image size, license and what not. Dispatch uses <a href="https://vmware.github.io/photon/">Photon OS</a> everywhere else, so we’ll use it here as well:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4036bf3f0388803c5d030b8a4f60246c/href">https://medium.com/media/4036bf3f0388803c5d030b8a4f60246c/href</a></iframe><h3>Add language runtime</h3><p>Usually you can install it with your package manager, e.g. for Node.js on vmware/photon2 that would look like this:</p><pre>tdnf install -y nodejs-8.3.0-1.ph2</pre><p>Our case is a bit different, because Clojure is a JVM language and I’d like to use the <a href="https://blog.docker.com/2018/04/improved-docker-container-integration-with-java-10/">container friendly Java 10</a> runtime, which Photon OS doesn’t provide. Also, turns out, vanilla <a href="http://jdk.java.net/10/">JDK 10</a> doesn’t want to “Just Work” on Photon OS, so we use <a href="https://www.azul.com/downloads/zulu/zulu-linux/">Zulu</a> (an excellent drop-in replacement):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/43fd367da62e421d818749262536a9ac/href">https://medium.com/media/43fd367da62e421d818749262536a9ac/href</a></iframe><p>Now we’ll fetch and install Leiningen and Clojure. <a href="https://leiningen.org/">Leiningen</a> (or lein) is a popular Clojure build and package manager based on <a href="http://maven.apache.org/">Maven</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e7642eead085048b0068669c1206d768/href">https://medium.com/media/e7642eead085048b0068669c1206d768/href</a></iframe><p>Now we have a solid Clojure runtime environment complete with package management tools in our base image.</p><h3>Create image template</h3><p>A Dispatch <em>base image</em> is supposed to have a directory to build <em>images</em> from. This directory should be specified in the <em>base image</em> metadata label <strong>io.dispatchframework.imageTemplate</strong> (the default value is /image-template):</p><pre>LABEL <strong>io.dispatchframework.imageTemplate</strong>=/image-template</pre><p>Typically, this directory only contains a Dockerfile:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/edd079a2d78865d8ee6193e308bbece5/href">https://medium.com/media/edd079a2d78865d8ee6193e308bbece5/href</a></iframe><p>This Dockerfile accepts 3 build arguments:</p><ul><li><strong>BASE_IMAGE</strong> — the <em>base image</em>, to build the <em>image</em> on top of</li><li><strong>SYSTEM_PACKAGES_FILE</strong> — lists required system packages in plain text format</li><li><strong>PACKAGES_FILE</strong> — library dependency manifest</li></ul><p>In the above Dockerfile, we read system packages from the file specified with SYSTEM_PACKAGES_FILE, make sure the list is not empty and has unique entries, and then install them with tdnf (Tiny DNF), the PhotonOS package manager.</p><p>Clojure uses <a href="https://clojure.org/reference/deps_and_cli">deps.edn</a> as its library manifest, so we just copy the provided file as deps.edn, and run clojure -Stree which fetches all the deps and lists them as a tree.</p><h3>Create function template</h3><p>A Dispatch <em>image</em> is supposed to have a directory to build <em>functions</em> from. This directory should be specified in the <em>image</em> metadata label <strong>io.dispatchframework.functionTemplate</strong> (the default value is /function-template):</p><pre>LABEL <strong>io.dispatchframework.functionTemplate</strong>=/function-template</pre><p>Since <em>images</em> are built on top of <em>base images</em>, we’re going to place that directory in our <em>base image</em>, and it will propagate to all derived images.</p><p>Typically, this directory only contains a Dockerfile:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bdd370a177c7c5e643bcf86f5c03dc04/href">https://medium.com/media/bdd370a177c7c5e643bcf86f5c03dc04/href</a></iframe><p>This Dockerfile accepts 2 build arguments:</p><ul><li><strong>IMAGE</strong> — <em>image</em>, to build <em>functions</em> on top of</li><li><strong>FUNCTION_SRC</strong> — function source code is copied into this file at build time</li></ul><p>We need to obtain the function and wrap it into the function server — an implementation of Function Runtime API.</p><p>We can run Clojure source files like scripts using clojure CLI tool. We add a couple lines to:</p><ol><li>Require our func-server.main namespace (the Function Runtime API implementation),</li><li>Grab the user-supplied function as <strong>function</strong> (by convention) and pass it as an argument to run our API server.</li></ol><h3>Implement Function Runtime API</h3><p>The <a href="https://vmware.github.io/dispatch/documentation/specs/language-support#function-runtime-api">Function Runtime API</a> server needs to wrap the user-supplied function and provide these endpoints:</p><pre>GET /healthz  - healthcheck<br>POST /*       - run function</pre><p>You can check out implementations for more languages on GitHub: <a href="https://github.com/dispatchframework">https://github.com/dispatchframework</a></p><p>Below is what needs to be done to implement it.</p><h4>Obtain the function from source code</h4><p>A function source code generally has enough information to fully define the function. For example, in JavaScript the function is assigned to module.exports — that’s all.</p><p>In Clojure it’s only slightly harder than in JavaScript. We just need a convention as to what function should be used as the entry point. This convention is up to the <em>base image</em>’s author, and needs to be clearly documented (the <em>base image</em>’s README is a good place).</p><p>In our case, as mentioned above, we will use a function named <strong>function</strong>, for example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/28f23ba01815dc92aeba8bc6b4a6396c/href">https://medium.com/media/28f23ba01815dc92aeba8bc6b4a6396c/href</a></iframe><p>Once we have the function, we <a href="https://github.com/dispatchframework/clojure-base-image/blob/master/func-server/src/func_server/routes.clj">construct a web app</a> from it and <a href="https://github.com/dispatchframework/clojure-base-image/blob/master/func-server/src/func_server/main.clj">launch it with an HTTP server</a>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1c811138aca60323b2a5bf142dbe3f4/href">https://medium.com/media/a1c811138aca60323b2a5bf142dbe3f4/href</a></iframe><h4>Implement the API endpoints</h4><p><a href="https://github.com/dispatchframework/clojure-base-image/blob/master/func-server/src/func_server/routes.clj">Implementing this simple API</a> in Clojure is straightforward: for each endpoint you need to provide functions mapping requests to responses. See (handle f) below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/27741abed61bc4e8db4943907c2d77b3/href">https://medium.com/media/27741abed61bc4e8db4943907c2d77b3/href</a></iframe><p>Constructing the web app from a function — that’s what (app f) does — is basically taking the function and threading it through some transformations: API handling, JSON request parsing and response encoding.</p><h4>Capture any thrown error and writes to stdout/stderr</h4><p>In the above web app, (core/wrap-func f) does all the important work — capturing error and logs:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7397120f67cf001c811f71063ac03ee4/href">https://medium.com/media/7397120f67cf001c811f71063ac03ee4/href</a></iframe><p>Again, threading of a function through some higher order functions. <a href="https://github.com/dispatchframework/clojure-base-image/blob/master/func-server/src/func_server/core.clj">Here’s the full source</a> — for the brave and true!</p><h3>Write README</h3><p>You definitely want your users to know how to get started with your new language pack. So, make sure to write up quick instructions in the <a href="https://github.com/dispatchframework/clojure-base-image/blob/master/README.md">README</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3515cce08e9f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dispatchframework/adding-a-language-to-dispatch-3515cce08e9f">Adding a Language to Dispatch</a> was originally published in <a href="https://medium.com/dispatchframework">dispatchframework</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Running containers from outside the box (with RancherOS and Docker Machine)]]></title>
            <link>https://medium.com/@imikushin/running-containers-from-outside-the-box-with-rancheros-and-docker-machine-27b1d64dfb4d?source=rss-8307b6d58a37------2</link>
            <guid isPermaLink="false">https://medium.com/p/27b1d64dfb4d</guid>
            <dc:creator><![CDATA[Ivan Mikushin]]></dc:creator>
            <pubDate>Thu, 11 Jun 2015 07:52:05 GMT</pubDate>
            <atom:updated>2015-07-06T11:39:41.471Z</atom:updated>
            <content:encoded><![CDATA[<p>Here’s a really quick Getting Started with RancherOS and Docker Machine:<br><em>(updated for Docker Machine v0.3.0, RancherOS v0.3.3)</em></p><p>01. Download latest <a href="https://github.com/docker/machine/releases">docker-machine binary</a>:</p><pre>brew install docker-machine</pre><p>02. Create a RancherOS machine with VirtualBox:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e94f2a3b4d8f84afa197b6783240717a/href">https://medium.com/media/e94f2a3b4d8f84afa197b6783240717a/href</a></iframe><p>03. Export the necessary environment for Docker CLI to access Docker API exposed by our new machine:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6e9d9830ddf20e75c024fe186c715bf/href">https://medium.com/media/c6e9d9830ddf20e75c024fe186c715bf/href</a></iframe><p>Here you are! Now you can use Docker API exposed by RancherOS.<br>Type</p><pre>docker info</pre><p>The output should be something like</p><pre>Containers: 0<br>Images: 0<br>Storage Driver: overlay<br> Backing Filesystem: extfs<br>Execution Driver: native-0.2<br>Logging Driver: json-file<br>Kernel Version: 3.19.8-ckt1-rancher<br>Operating System: &lt;unknown&gt;<br>CPUs: 1<br>Total Memory: 999.5 MiB<br>Name: ros-033<br>ID: SPPI:POMV:X7DK:4DY4:NM4A:XRCC:RJGF:BXYE:CT6S:37ZU:KZXC:XIUH<br>Username: imikushin<br>Registry: <a href="https://index.docker.io/v1/">https://index.docker.io/v1/</a><br>Labels:<br> provider=virtualbox</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=27b1d64dfb4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Running Kubernetes cluster on RancherOS]]></title>
            <link>https://medium.com/@imikushin/running-kubernetes-cluster-on-rancheros-b2bd1308eb6d?source=rss-8307b6d58a37------2</link>
            <guid isPermaLink="false">https://medium.com/p/b2bd1308eb6d</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[rancheros]]></category>
            <dc:creator><![CDATA[Ivan Mikushin]]></dc:creator>
            <pubDate>Tue, 17 Mar 2015 19:21:53 GMT</pubDate>
            <atom:updated>2015-03-17T19:21:53.460Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://github.com/rancherio/os">RancherOS</a> is the smallest (and arguably the coolest) operating system to run Docker containers. How about running distributed apps, made of <strong>lots of containers</strong> providing different services to each other? One of emerging technologies to serve that purpose is <a href="http://kubernetes.io/">Kubernetes</a>.</p><p>I’m going to show you how to run Kubernetes on RancherOS. We’ll use <a href="https://www.vagrantup.com/">Vagrant</a> for a quick start.</p><h4>TL;DR</h4><p>To begin <strong>using</strong> Kubernetes on RancherOS it, just clone this GitHub repo and follow the README:<br><a href="https://github.com/imikushin/rancheros-k8s-vagrant">https://github.com/imikushin/rancheros-k8s-vagrant</a></p><p>To learn what are Kubernetes’ essential parts and how to deploy it yourself, read on.</p><h3>Tools</h3><h4>Vagrant</h4><p>We’ll need a multi-machine cluster of RancherOS VMs. The easiest way to start is Vagrant, so I’ve hacked a <a href="https://github.com/imikushin/rancheros-cluster-vagrant">Vagrant box and Vagrantfile</a> to do just that (stay tuned for an upcoming “prequel” post). You can clone the <a href="https://github.com/imikushin/rancheros-cluster-vagrant">repo</a>, run “vagrant up” in its dir, and here you are with a few ready to use RancherOS VMs accessible with “vagrant ssh” and ready to communicate via a host-only VirtualBox network.</p><h4>Docker</h4><p>If you want to run anything on RancherOS, you’re going to run it in a Docker container, or a bunch of containers, in our case. For running infrastructure services like Kubernetes, RancherOS has a tool called “system-docker”.</p><p>All the necessary components are packaged into <a href="https://github.com/imikushin/rancheros-k8s-vagrant/tree/master/src/dockerimages">these containers</a>:</p><ul><li>imikushin/flannel — contains <a href="https://github.com/coreos/flannel">flannel</a> and <a href="https://github.com/coreos/etcd">etcd</a> binaries</li><li>imikushin/kubernetes — contains all <a href="https://github.com/GoogleCloudPlatform/kubernetes">kubernetes</a> binaries</li></ul><p>These are not specific to RancherOS, and you can use them to run Kubernetes anywhere.</p><h3>Architecture</h3><p><strong>How</strong> exactly does one run Kubernetes? Previously, I’d had it run for me by <a href="https://github.com/GoogleCloudPlatform/kubernetes/tree/master/cluster">shell scripts</a> from its distribution or by existing Vagrant configurations like <a href="https://github.com/pires/kubernetes-vagrant-coreos-cluster">this one</a>. So, that was the question I asked myself when I just started this little project.</p><p>I’ve found a good <a href="https://www.digitalocean.com/community/tutorials/an-introduction-to-kubernetes">introduction to Kubernetes</a> on DigitalOcean Community. Basically, Kubernetes is a bunch of <strong>processes</strong> on master and minion nodes, collaborating to provide a distributed container runtime, manageable via a RESTful API on the master node.</p><p><a href="https://github.com/imikushin/rancheros-k8s-vagrant/blob/master/src/start-k8s-master.sh">Master processes</a> are:</p><ul><li>kube-apiserver — you know, the API server</li><li>kube-controller-manager — handles replication</li><li>kube-scheduler — assigns workloads to minion nodes</li></ul><p><a href="https://github.com/imikushin/rancheros-k8s-vagrant/blob/master/src/start-k8s-minion.sh">Minion processes</a> are:</p><ul><li>kubelet — receives commands and work from the master</li><li>kube-proxy — exposes the deployed containers to clients</li></ul><p><a href="https://github.com/imikushin/rancheros-k8s-vagrant/blob/master/src/start-node.sh">Common processes</a> are:</p><ul><li>etcd — cluster key-value store, needed by almost all other k8s processes</li><li>flannel — provides cluster-wide overlay network</li><li><a href="https://github.com/imikushin/rancheros-k8s-vagrant/blob/master/src/dockerimages/scripts/k8s-docker.sh">docker daemon</a>, configured to use flannel overlay network</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Mo8ZgGNbWl8r9o9-qcegw.png" /><figcaption>Kubernetes architecture. Source: <a href="https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/architecture.svg">Kubernetes project</a></figcaption></figure><p>Let’s build our own Kubernetes cluster. We’ll start with a multiple RancherOS machines deployed with Vagrant/VirtualBox:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/30527e004557773232a7f30ca4f0cd6d/href">https://medium.com/media/30527e004557773232a7f30ca4f0cd6d/href</a></iframe><p>We’ll put our host scripts (to be run on the host machine only) to ‘scripts’ dir and all other sources to ‘src’ (we already have it). To start the VMs, run</p><pre>vagrant up</pre><p>So, we have a bunch of VMs with RancherOS started with Vagrant. Now we need these VMs to run the processes according to their roles (master or minion). Let’s consider ‘node-01’ to be the master:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c48a0a6090f02e06905b8a0ff294472c/href">https://medium.com/media/c48a0a6090f02e06905b8a0ff294472c/href</a></iframe><p>We’ll check for ‘.k8s-master’ file later.</p><h3>Common processes</h3><h4>etcd</h4><p>All cluster nodes run <strong>etcd</strong>, a distributed configuration database, needed by <strong>flannel</strong>, <strong>kubelet</strong>, <strong>kube-proxy</strong> and <strong>kube-apiserver</strong>.</p><p>You want your <strong>etcd</strong> cluster to <a href="https://github.com/coreos/etcd/blob/master/Documentation/clustering.md">configure itself</a> somehow (otherwise you’ll have to provide static addresses of all nodes to every <strong>etcd</strong> instance). This feature is called discovery. Luckily, there’s a <a href="https://github.com/coreos/etcd/blob/master/Documentation/clustering.md#public-etcd-discovery-service">public etcd discovery service</a>, and we’re going to use it. We’re not running this in production, so let’s specify the cluster size=1: the first node to boot (‘node-01’) is becoming the only “real” participant, the others to become “proxies”.</p><p>In order to provide fresh discovery URL, we have to run this script on our host <strong>every time</strong> before <strong>bringing up</strong> our cluster:</p><pre>./scripts/etcd-discovery</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6437bd384dc638057d83ef1eb0f28e8/href">https://medium.com/media/c6437bd384dc638057d83ef1eb0f28e8/href</a></iframe><p>‘.etcd-discovery-url’ file will be provisioned to all our machines by Vagrant on every boot:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e15275531142c23b5865bf5274d3ed44/href">https://medium.com/media/e15275531142c23b5865bf5274d3ed44/href</a></iframe><p>We’re running <strong>etcd</strong> with ‘--discovery’ option containing the generated discovery URL:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/221c4b59358fedcc36b26dd31dcd9874/href">https://medium.com/media/221c4b59358fedcc36b26dd31dcd9874/href</a></iframe><p>For details on REGISTRY_MIRROR environment variable, see below.</p><h4>flannel</h4><p>All cluster nodes will run <strong>flannel</strong>, an overlay network for deployed containers communication. There are other options like <a href="https://zettio.github.io/weave/">Weave</a> and <a href="https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/ovs-networking.md">OpenVSwitch</a>, but <strong>flannel</strong> is much easier to start with on a small local cluster.</p><p>We need to save <strong>flannel</strong> configuration to <strong>etcd</strong>, first:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba153a6e3f7c07ad1aab071478500657/href">https://medium.com/media/ba153a6e3f7c07ad1aab071478500657/href</a></iframe><p>That script is actually run inside ‘imikushin/flannel’ container, that has <strong>etcdctl</strong> installed:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e20c09c17f8f89e44ea1e9c64f90eb5/href">https://medium.com/media/2e20c09c17f8f89e44ea1e9c64f90eb5/href</a></iframe><p>We also need to provide ‘FLANNEL_NETWORK’ which specifies our overlay network IP address space (in CIDR notation).</p><p>Now we can run <strong>flannel</strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/177b5cfe4ae7e497254cab053294d67d/href">https://medium.com/media/177b5cfe4ae7e497254cab053294d67d/href</a></iframe><h4>Docker daemon</h4><p>RancherOS has a system container called ‘userdocker’ responsible for running the docker daemon for user containers. We need to replace it with our customized docker daemon (currently, we can’t simply pass ‘userdocker’ the network configuration we need):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/587c7e4afa258277939409c77e9b57c6/href">https://medium.com/media/587c7e4afa258277939409c77e9b57c6/href</a></iframe><p>For the machine to be able to participate in a Kubernetes cluster, its docker daemon should be configured to run deployed containers on the overlay network.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/64700f879f1cc3492497e7512912bb9e/href">https://medium.com/media/64700f879f1cc3492497e7512912bb9e/href</a></iframe><p>We’re sourcing ‘/var/run/flannel/subnet.env’ produced by <strong>flannel</strong> daemon and using FLANNEL_SUBNET and FLANNEL_MTU variables from it to configure docker daemon for Kubernetes.</p><h3>Master processes</h3><p>Now that we have common processes, we can start master and minion specific processes. But there’s just one thing before we go.</p><p>Minions need to know Kubernetes master API endpoint to start ‘kubelet’ process, so let’s publish it to etcd:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7379d4b0b24aa9268c5d98a385ac6433/href">https://medium.com/media/7379d4b0b24aa9268c5d98a385ac6433/href</a></iframe><h4>kube-apiserver</h4><p>Start Kubernetes API server:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/952f67c072e227b47b8bcfb4a268d3c2/href">https://medium.com/media/952f67c072e227b47b8bcfb4a268d3c2/href</a></iframe><p>About the ‘--portal_net=10.0.0.0/16’ magic constant: see discussion below<br>(in the <strong>kube-proxy</strong> section).</p><h4>kube-controller-manager</h4><p>Start Kubernetes Controller Manager:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5284b950e8cfc386c806e60780cc67ea/href">https://medium.com/media/5284b950e8cfc386c806e60780cc67ea/href</a></iframe><h4>kube-scheduler</h4><p>Start Kubernetes Scheduler:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f74fb6ca68565b49772c7379d4abaec7/href">https://medium.com/media/f74fb6ca68565b49772c7379d4abaec7/href</a></iframe><h3>Minion processes</h3><p>First, let’s retrieve the Kubernetes API server endpoint saved by master on boot — we’ll need this value for ‘kubelet’ service:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be3eda4f20d590204c17713aa03049e3/href">https://medium.com/media/be3eda4f20d590204c17713aa03049e3/href</a></iframe><h4>kube-proxy</h4><p>Start Kubernetes Proxy:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4e6218e887685c9ed03b47605a81a01/href">https://medium.com/media/c4e6218e887685c9ed03b47605a81a01/href</a></iframe><p>Just a quick note about the ‘--portal_net’ magic constant above (in the <strong>kube-apiserver</strong> section). It is a network address space for services exposed by pods deployed to the Kubernetes cluster. It is used by <strong>kube-proxy</strong> to expose these services to clients (primarily, other deployed pods).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*41bsj7xO-PPGIK4iXc3aZw.png" /><figcaption>Service proxying details. Source: <a href="https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/services_detail.png">Kubernetes project</a></figcaption></figure><h4>kubelet</h4><p>Start Kubelet service:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/22842db78a8270ce1852958a2408ab17/href">https://medium.com/media/22842db78a8270ce1852958a2408ab17/href</a></iframe><h4>Register minion with the master</h4><p>There’s one last thing we need to do: register just created minion node with the API server. One would expect <strong>kubelet</strong> to register itself with the API server on start (it has API server’s address, right?), but that doesn’t happen. So, we must step up and do this for them:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/19eecd51ac3b585ceb9183a49310492a/href">https://medium.com/media/19eecd51ac3b585ceb9183a49310492a/href</a></iframe><h3>Almost there</h3><p>Now, because we have ‘.k8s-master’ file provisioned to our master node, it’s trivial to decide whether to run ‘start-k8s-master.sh’ or ‘start-k8s-minion.sh’:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ccb5a437f849dbe62ca6c68c430c126/href">https://medium.com/media/2ccb5a437f849dbe62ca6c68c430c126/href</a></iframe><p>Just a few more things left todo.</p><h4>Remove stale containers</h4><p>When writing your start scripts on RancherOS, beware of old stopped (but not removed) containers. RancherOS won’t remove them for us, so it’s a good idea to remove them before running new instances, e.g. like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/877e67c93f66d72b4480e7245328f571/href">https://medium.com/media/877e67c93f66d72b4480e7245328f571/href</a></iframe><p><strong>Make sure</strong> you do this for <strong>all named containers</strong> you run (not only those with ‘-d’ flag): Docker won’t let you run another container with the same name.</p><h4>REGISTRY_MIRROR</h4><p>You might want to run a Docker registry mirror on your host machine, to reduce container images downloads:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f6ef6d02baaf83526587d6612747431a/href">https://medium.com/media/f6ef6d02baaf83526587d6612747431a/href</a></iframe><p>Here’s a script to get the registry mirror endpoint on a cluster node:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/86bf706c4892ff3723899c45fbb47576/href">https://medium.com/media/86bf706c4892ff3723899c45fbb47576/href</a></iframe><h4>Detach the start script</h4><p>Let’s make our start script execute in the background and move on:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b66ef29265327314538f809ba4dc660/href">https://medium.com/media/7b66ef29265327314538f809ba4dc660/href</a></iframe><h4>Finish the Vagrantfile</h4><p>Make sure you provision all your scripts to cluster nodes and launch the start script:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/57babef222f1d5de8918fa36502df23f/href">https://medium.com/media/57babef222f1d5de8918fa36502df23f/href</a></iframe><p>That’s it: now we have all the necessary services in place and can use our shiny new Kubernetes cluster (something <a href="https://github.com/imikushin/rancheros-k8s-vagrant">like this</a>):</p><pre>./scripts/etcd-discovery; vagrant up</pre><p>Okay, let’s try something: you can explore Kubernetes REST API with “swagger-ui”. My MASTER_IP is 172.28.128.3, so I’ll open the following URL in my browser:<br><a href="http://172.28.128.3:8080/swagger-ui/">http://172.28.128.3:8080/swagger-ui/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6jNm6YprPJy8KFEn9kso4w.png" /></figure><p>Looks like master is accessible.</p><p>Okay, here’s another check. Make sure you have <a href="https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/kubectl.md"><strong>kubectl</strong></a> installed on your local machine and have KUBERNETES_MASTER environment variable set to</p><pre>http://${MASTER_IP}:8080</pre><p>where MASTER_IP is your cluster master (‘node-01’) IP address.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a7f82e59f26cff51cda62fc6ef5d3d2/href">https://medium.com/media/0a7f82e59f26cff51cda62fc6ef5d3d2/href</a></iframe><p>All right, looks like we have the minions ready.</p><p>Now, go ahead and try some <a href="https://github.com/GoogleCloudPlatform/kubernetes/tree/master/examples">Kubernetes examples</a> with your new cluster. Smooth sailing!</p><h3>Resources</h3><p><a href="https://github.com/rancherio/os">RancherOS</a> project.</p><p><a href="https://docs.vagrantup.com/v2/">Vagrant documentation</a>.</p><p>I’ve already mentioned <a href="https://www.digitalocean.com/community/tutorials/an-introduction-to-kubernetes">An Introduction to Kubernetes</a> on DigitalOcean Community.</p><p><a href="https://github.com/pires/kubernetes-vagrant-coreos-cluster">kubernetes-vagrant-coreos-cluster</a>, found on the Kubernetes <a href="https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/getting-started-guides/coreos.md">Getting Started on CoreOS</a> page was of great help to understand the moving parts.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b2bd1308eb6d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>