Newbernetes: Getting Started; Kubernetes on Docker

Cory O'Daniel
Feb 17, 2018 · 4 min read

Back in Octoberish 2017, Docker (the company) announced that Docker (the project) would support Kubernetes for container orchaestration and that they would be releasing it bundled with Docker for Mac!

Before Docker supported Kubernetes it required a bit of work to get Kuberenetes set up to develop and experiment with locally. Usually one would use something like Minikube which is a great project, but always felt a little bumpy to me.

Great, so what is docker?

Docker is the world’s leading software containerization platform.

Obvi.

If you aren’t familiar with docker its a great way to package up your applications and their dependencies into little lovely bundles (called images) and deploy them (containers) with little fuss. You probably knew that already so, moving right along.

What is kubernetes?

Kubernetes is an open-source platform designed to automate deploying, scaling, and operating application containers.

tl;dr: It runs your containerized apps and helps keep them highly available.

Cool, lets make something. First step is to install Docker Edge. Note, if you have the docker stable channel, installing edge will probably delete your local docker images, so be warned if you already have docker running on your machine.

Head on over to your operating system:

Download the Edge version.

This installs a bunch of docker command line tools, but don’t trip chocolate chip, YAGNI for this tutorial. Let’s pop open a terminal and make sure the version looks right. You should see this version or greater.

docker --versionDocker version 18.02.0-ce-rc2, build f968a2c

By default Kubernetes isn’t enabled, so let’s enable that.

Click the little Whale with all the containers on his back. Click “Preferences…” > “Kubernetes” and check the little box. Go do something fun, this takes a minute or two.

Someone call, PETA, thats a lotta containers!
Checkadabox
Go get a coffee, pet a dog, or sword fight someone.

And finally install the Kubernetes CLI tools. This CLI will be used to control applications and other resources in your cluster. Install with homebrew on Mac:

brew install kubectl

Installing kubectl on other operating systems is outlined here.

Finally we’ll install an optional but very useful tool for managing multiple clusters and namespaces called kubectx. Instructions are here for other operating systems.

brew install kubectx

When working with kubernetes you may have multiple “contexts.” You can end up with a number of different clusters (production, staging, beta, etc) as well as different user roles you have to access them (cluster-admin, application-admin, etc). A context is a user’s access to the cluster.

I like using kubectx because its really easy to switch between contexts and namespaces.

Run:

kubectx # and it should output something like:docker-for-desktop # <- this is what you are looking for
minikube # <--|
hab-prod # <--|
hab-stage# <--|- these are other clusters I have contexts for
col-prod # <--|
col-stage# <--|

If docker-for-desktop isn’t highlighted, run the following to select it:

kubectx docker-for-desktop

Now verify that your single node Kubernetes cluster is running:

kubectl get nodesNAME                 STATUS    ROLES     AGE       VERSION
docker-for-desktop Ready master 10m v1.9.2

Wild, huh?

Namespaces are something else I prefer to start with. They provide a level of security and organization around resources and applications. The official docs suggest you don’t start with them because its unnecessary overhead to reason about.

Namespaces are useful as scopes for a team or a project. They can also be used for applying resource quotas and controlling access through roles. kubectx also includes kubens for switching namespaces.

kubensdefault # <- where kube resources go by default
docker # <- where docker's kube resources are
kube-public # <- publicly visible connection info for the cluster
kube-system # <- kubernetes guts

But most importantly for a tutorial: deleting a namespace will delete all the resources in it. So it makes for really easy clean up!

Check out Part 2 for getting familiar with kubectl!

CoryODaniel

Notes on SQL, ruby, elixir, tacos, and whiskey

Cory O'Daniel

Written by

SQL, kubernetes, elixir, ruby, node, tacos, whiskey, repeat.

CoryODaniel

Notes on SQL, ruby, elixir, tacos, and whiskey

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade