The container orchestration handwriting is on the wall, and it reads "Kubernetes." But how do you learn Kubernetes before trying to deploy it? Minikube is the program for you.

Containers have become the way everyone deploys applications. And Kubernetes has become the favorite container orchestration tool.

As such, it behooves anyone working with containers or the cloud—which is pretty much everyone in enterprise IT—to improve their Kubernetes skills. That’s both to benefit your company and your own career prospects.

Unfortunately, setting up Kubernetes on a cloud is difficult. You can spend more time getting it to work than learning how to use it.

The solution: Minikube. Minikube is an application that brings you up to speed. It helps you set up and run Kubernetes on a computer running Linux, macOS, or (in beta) Windows. You can avoid Kubernetes' steep deployment learning curve and get straight to trying out the container management tool’s features.

But even Minikube needs an introduction. In this article, I show you the steps involved in using Minikube, using Linux as my operating system.

What’s in the (virtual) box

Minikube supports almost all Kubernetes features, specifically:

DNS

NodePorts

ConfigMaps and Secrets

Dashboards

Container Runtime: Docker, rkt, cri-o, and containerd

Container Network Interface (CNI)

Ingress

Since Minikube runs locally, some cloud-specific Kubernetes features, such as LoadBalancers and PersistentVolumes, do not work out of the box. In any case, Minikube gives you more than enough to get your feet wet.

Minikube runs a single-node Kubernetes cluster inside a virtual machine. Specifically, Minikube is built on top of Docker’s libmachine. Minikube isn’t demanding of system resources. By default, it requires 1 GB of RAM and a processor with Intel VT-X or AMD-V. In short, you can run it on pretty much any PC.

(Alternatively, you can run Minikube natively on a Linux system. To do this, you must have Docker installed and run Minikube with the --vm-driver=none option. If you go this way, you must also specify a Docker bridge network or you may lose network connectivity to your cluster when its network restarts.)

Kubernetes basics

Before going further, let's take a brief look at Kubernetes architecture as a refresher course. More in-depth explanations are found in my earlier articles "Container orchestration primer: Explaining Docker swarm mode, Kubernetes, and Mesosphere" and "How to implement cloud-native computing with Kubernetes."

Unsure how to get started with containers? Yes, we have a guide for that. Get Containers for Dummies. Download now

Kubernetes is a distributed computing platform with a loosely coupled mechanism for service discovery. A Kubernetes cluster is made up of at least one master and compute node. The master exposes the API and schedules the clusters’ deployments and management.

Each node runs a container runtime, such as Docker, and an agent that communicates with the master. Nodes also run logging, monitoring, service discovery, and other services. Nodes expose compute, networking, and storage resources to applications. Typically, a node is a VM, but it can also be a standard server.

Pods, which are collections of one or more nodes, are Kubernetes’ core unit of management. Pods contain nodes sharing the same context and resources. Pods make it possible to run multiple dependent processes and containers together.

Kubernetes abstracts the differences between the applications and their underlying infrastructure. This makes it possible, with Federation, to run clusters on multiple cloud providers and on premises. This enables you to run hybrid clouds with Kubernetes-based applications providing microservices across multiple platforms simultaneously.

Getting ready to install Minikube

Before installing Minikube, you need to:

Install a VM. For Linux, that means either Oracle's VirtualBox or Linux's native KVM.

Install the Kubernetes command-line interface, kubectl.

Add shell completion functionality.

If you have all the components in place, setting up Minikube shouldn't take you more than five minutes. If you're starting from scratch, expect it to take a few hours.

Once the VM is installed, install the Kubernetes command-line tool, kubectl. Without it, you can't work with Minikube. That does take a few steps.

If you're running a Debian-based Linux distribution, use these commands:

sudo apt-get update && sudo apt-get install -y apt-transport-https

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list

sudo apt-get update

sudo apt-get install -y kubectl

If you're using a Red Hat-based distribution, run:

cat <<EOF > /etc/yum.repos.d/kubernetes.repo

[kubernetes]

name=Kubernetes

baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64

enabled=1

gpgcheck=1

repo_gpgcheck=1

gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg

EOF

yum install -y kubectl

Once you're back to the shell prompt, you're good.

That done, it's a good idea to enable bash shell completion, because kubectl commands can be long and complicated even by shell command standards. In addition, automatically created pod names include hashes, which are painful to type at the best of times.

To do this, open your ~/.bashrc file in your favorite editor and add anywhere therein:

source <(kubectl completion bash)

For further details, run kubectl completion -h .

Installing Minikube

Minikube is constantly evolving. As I write this, the latest version is 0.30. But to make sure you're using the latest and greatest, follow the Minikube's GitHub repository's instructions.

I am here to give you a high-level overview, though, so you can get to work quickly. So install Minikube by typing at a command line:

curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.30.0/minikube-linux-amd64 && chmod +x minikube && sudo cp minikube /usr/local/bin/ && rm minikube

Minikube is made up of a binary executable and an ISO VM image. Without both, Minikube won't run. To verify the contents of your distribution, compare the binary's sha256 hashes with this value:

$ tail -n +1 -- out/*.sha256

==> out/minikube-linux-amd64.sha256 <==

f6fcd916adbdabc84fceb4ff3cadd58586f0ef6e576233b1bd03ead1f8f04afa

And for the ISO:

$ openssl sha256 minikube.iso

SHA256(minikube.iso)=

63ddb9cc2db1816a18c76b95cb6ea93acb9a912f5faf37677ab3d2436a45056f

Minikube includes a built-in Docker daemon. That means you don't have to install Docker or build a Docker registry in order to push your container images into it. (See, one more way in which Minikube eases the Kubernetes learning process!) To work with the Minikube docker daemon, in your shell, use the docker-env command:

eval $(minikube docker-env)

And that's it. You now have Minikube ready to go on your PC—once you can talk to it.

For kubectl to work with a Kubernetes cluster, it needs a kubeconfig file. This is created automatically when you deploy your first Minikube cluster.

Running Minikube

To start up Minikube, from your shell, type:

$ minikube start

Minikube start: Ready, set, start Minikube!

You can also start up Minikube preconfigured with the --extra-config flag. This flag takes options using the grammar component.key=value .

When you're done tinkering with Minikube, you can stop Kubernetes VM with the command:

$ minikube stop

This command keeps your cluster state and data. Starting the cluster again restores it to its previous state.

Note that if you reboot your system, you lose your Kubernetes cluster. That's because, by default, Minikube files and directories are temporary file systems (tmpfs). If you want, you can create persistent volumes within the Kubernetes VM. To stop your Kubernetes cluster and delete your records, type:

$ minikube delete

Working with Minikube

Once Minikube's up and running, you use kubectl shell tool to work with it. Begin with the command:

$ kubectl config view

This ensures you can reach Minikube and provides you with its IP and port address and its cluster and usernames.

Minikube config: kubectl config gives you a quick overview of Minikube's foundational setup.

If you aren’t so much a command-line person, you can also access Minikube with a web interface by running the command:

$ minikube dashboard

This launches your default web browser for your cluster's web interface.

Next, you need to load and run an application on your newly minted Kubernetes cluster. To keep things simple for the sake of examples, start by installing Helm, Kubernetes' package manager, using the commands:

$ curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get > get_helm.sh

$ chmod 700 get_helm.sh

$ ./get_helm.sh

Using Helm charts, you can easily set up Helm-containerize applications. A Helm chart contains an application's metadata and the Kubernetes infrastructure instructions needed to operate it. Helm charts are made up of an application package description using YAML Ain't Markup Language (YAML) and templates containing Kubernetes manifest files.

Then get Helm ready to run:

$ kubectl create serviceaccount -n kube-system tiller

$ kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller

$ helm init --service-account tiller

Next, install Helm-containerized Redis, the in-memory data structure store, from the default GitHub Helm Charts. Run:

$ helm install stable/redis --set serviceType=NodePort

(Note that the flag for the serviceType is set because Minikube doesn't support load balancing.)

When you switch over to Dashboard, you should see Redis up and running.

Kubernetes Dashboard: After all those shell commands, Dashboard gives you a web interface to Kubernetes.

So there you go! You've got Minikube up and running and applications doing their thing. Now you're ready to start tinkering with Kubernetes.

That’s just the beginning

In this article, I aim to give a simple overview, but naturally there are plenty more ways to configure Minikube. See kubelet; apiserver; proxy; controller-manager; etcd; and scheduler. For example, to make sure your system resources don't get overwhelmed, you could set the maximum number of pods running per core with the command:

$ minikube start --extra-config=kubelet.PodsPerCore=5

Ready to dive deeper? For the next step on your road to mastering Kubernetes, read "Hello Minikube." Then follow up with "Learn Kubernetes in Under 3 Hours: A Detailed Guide to Orchestrating Containers." With that under your belt, I recommend Kelsey Hightower's master class, Kubernetes the Hard Way.

Given how popular containers and Kubernetes are becoming, it's well worth the journey.