<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Containers on CodeGoalie</title><link>https://codegoalie.com/categories/containers/</link><description>Recent content in Containers on CodeGoalie</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Thu, 04 Feb 2016 15:11:50 -0500</lastBuildDate><atom:link href="https://codegoalie.com/categories/containers/index.xml" rel="self" type="application/rss+xml"/><item><title>Working with Containers: beyond the tutorial</title><link>https://codegoalie.com/posts/working-with-containers/</link><pubDate>Thu, 04 Feb 2016 15:11:50 -0500</pubDate><guid>https://codegoalie.com/posts/working-with-containers/</guid><description>&lt;p>Over the past few months, I&amp;rsquo;ve been getting my hands dirty with containers,
Docker, and Kubernetes in an effort to get some hands on experience working
toward microservices. I&amp;rsquo;ve been building up a small application to generate and
serve Sudoku puzzles. My original goal was to see how many puzzles with unique
solution I could actually find, but that&amp;rsquo;s another post entirely. There are
already
&lt;a href="https://docs.docker.com/engine/userguide/basics/">many&lt;/a>
&lt;a href="http://kubernetes.io/v1.1/examples/guestbook-go/README.html">great&lt;/a>
&lt;a href="https://cloud.google.com/container-engine/docs/tutorials/guestbook">tutorials&lt;/a>
about
&lt;a href="https://docs.docker.com/">Docker&lt;/a>
and
&lt;a href="http://kubernetes.io/v1.1/docs/whatisk8s.html">Kubernetes&lt;/a>
on &lt;a href="https://cloud.google.com/container-engine/docs/">Google Container Engine&lt;/a>,
so I won&amp;rsquo;t go into getting started details here. This post is meant to explain
some of the stickier points that I had to pickup the hard way. I hope to save
you one or two headaches.&lt;/p>
&lt;!-- raw HTML omitted -->
&lt;h2 id="turn-key-kubernetes">Turn Key Kubernetes&lt;/h2>
&lt;p>Typically, I&amp;rsquo;ve used AWS for my infrastructure needs, but Google Container
Engine runs kubernetes for you and can spin up a new cluster with one command.
Again, there are many tutorials about the specifics but here are a few things I
didn&amp;rsquo;t know going in which would have been helpful.&lt;/p>
&lt;h3 id="keeping-costs-down">Keeping costs down&lt;/h3>
&lt;p>By default your cluster is composed of 3 &lt;code>n1-standard-1&lt;/code> instances. When just
getting started this is probably more than you need in both resources and cost.
Since I was more interested in playing with containers than messing with
compute engine instances (that&amp;rsquo;s the whole point of containers), I didn&amp;rsquo;t pay
any attention to them, but you should. It&amp;rsquo;s super easy and quick to change both
the number of instances and the instance types in your cluster.&lt;/p>
&lt;p>Google Container Engine clusters are built on the idea of &lt;a href="https://cloud.google.com/compute/docs/instance-groups/">instance
groups&lt;/a>, which
are just one or more instance defined by the same &lt;a href="https://cloud.google.com/compute/docs/instance-templates">instance
template&lt;/a>. The
template described the instances you want in your group with attributes like
machine type and base image, etc. In the Google Cloud Console, you can design
a new template right in the interface (pick a new machine type from a drop down)
and use smaller or larger instances.&lt;/p>
&lt;p>Scaling the number of instances in your cluster is even easier. Edit the
Instance Group and change the &amp;ldquo;Number of Instances&amp;rdquo; textbox value. You can even
enter 0 to stop getting billed for the instance time. This works great when you
don&amp;rsquo;t need the instances to be up 24/7 while just playing around.&lt;/p>
&lt;h3 id="persistent-storage">Persistent Storage&lt;/h3>
&lt;p>When a pod is restarted or rescheduled, it gets recreated from scratch. Anything
that was stored on disk is gone. This can cause unexpected issues. For example,
I was using redis for storing Sudoku puzzles and if the redis-master pod
restarted, I lost all contents of the database. This can be unexpected because
when running redis locally, the disk snapshots always remain even when
restarting the redis-server process. With containers, this is not the case. If
you need to store anything to disk that you care about, you&amp;rsquo;ll need to store
that in a volume backed by a Google Persistent Disk. Once again, there are many
tutorials on the specifics.&lt;/p>
&lt;h3 id="stuck-in-creatingcontainer">Stuck in CreatingContainer&lt;/h3>
&lt;p>When using a Google persistent disks, I was running into pods getting
rescheduled onto new nodes (instance), but the disk remained attached to the
previous node. Since Google Cloud persistent disks can only be attached to one
node at a time, this caused the pod to hang during creation and never start.
The quick fix to this is just detach the disk from it&amp;rsquo;s current node.
Kubernetes will attach it to the correct node for you.&lt;/p>
&lt;pre>&lt;code>gcloud compute instances detach-disk &amp;lt;instance-name&amp;gt; --disk &amp;lt;disk-name&amp;gt;
&lt;/code>&lt;/pre>&lt;p>There&amp;rsquo;s currently an effort to redesign the volumne mount/dismount system in
Kubernetes to address this issue. I also think that as redis was maxing out the
memory on the nodes and crashing, it was causing unnecessary havok on my
cluster.&lt;/p>
&lt;h2 id="restarting-a-pod">&amp;ldquo;Restarting&amp;rdquo; a pod&lt;/h2>
&lt;p>Early on my Sudoku generator was very naive and had exponention performance, so
it would get &amp;ldquo;stuck&amp;rdquo; trying to come up with new puzzles. Locally, I was just
restarting the process. But when I got it into the cluster, it wasn&amp;rsquo;t always
clear if it was broken, or just getting held up (I did fix this and went from
a puzzle every few minutes to a few puzzles a second). The great feature of
using replication controllers is that it will keep the specified number of pods
running. So to &amp;ldquo;restart&amp;rdquo; a pod that&amp;rsquo;s being managed by a replication controller,
just delete it. The replication controller will bring up a new one. If you
aren&amp;rsquo;t using a replication controller to manage your pods, do so.&lt;/p>
&lt;p>Hopefully these tips will make your container journey a little smoother.&lt;/p></description></item></channel></rss>