You are viewing documentation for Kubernetes version: v1.22
Kubernetes v1.22 documentation is no longer actively maintained. The version you are currently viewing is a static snapshot. For up-to-date documentation, see the latest version.
Running Kubernetes locally on Linux with Minikube - now with Kubernetes 1.14 support
Author: Ihor Dvoretskyi, Developer Advocate, Cloud Native Computing Foundation
A few days ago, the Kubernetes community announced Kubernetes 1.14, the most recent version of Kubernetes. Alongside it, Minikube, a part of the Kubernetes project, recently hit the 1.0 milestone, which supports Kubernetes 1.14 by default.
Kubernetes is a real winner (and a de facto standard) in the world of distributed Cloud Native computing. While it can handle up to 5000 nodes in a single cluster, local deployment on a single machine (e.g. a laptop, a developer workstation, etc.) is an increasingly common scenario for using Kubernetes.
A few weeks ago I ran a poll on Twitter asking the community to specify their preferred option for running Kubernetes locally on Linux:
Ok, Twitter ✋— ihor dvoretskyi (@idvoretskyi) February 6, 2019
Your local Kubernetes cluster on Linux is deployed by:
This is post #1 in a series about the local deployment options on Linux, and it will cover Minikube, the most popular community-built solution for running Kubernetes on a local machine.
Minikube is a cross-platform, community-driven Kubernetes distribution, which is targeted to be used primarily in local environments. It deploys a single-node cluster, which is an excellent option for having a simple Kubernetes cluster up and running on localhost.
Minikube is designed to be used as a virtual machine (VM), and the default VM runtime is VirtualBox. At the same time, extensibility is one of the critical benefits of Minikube, so it's possible to use it with drivers outside of VirtualBox.
By default, Minikube uses Virtualbox as a runtime for running the virtual machine. Virtualbox is a cross-platform solution, which can be used on a variety of operating systems, including GNU/Linux, Windows, and macOS.
At the same time, QEMU/KVM is a Linux-native virtualization solution, which may offer benefits compared to Virtualbox. For example, it's much easier to use KVM on a GNU/Linux server, so you can run a single-node Minikube cluster not only on a Linux workstation or laptop with GUI, but also on a remote headless server.
Unfortunately, Virtualbox and KVM can't be used simultaneously, so if you are already running KVM workloads on a machine and want to run Minikube there as well, using the KVM minikube driver is the preferred way to go.
In this guide, we'll focus on running Minikube with the KVM driver on Ubuntu 18.04 (I am using a bare metal machine running on packet.com.)
This is not an official guide to Minikube. You may find detailed information on running and using Minikube on it's official webpage, where different use cases, operating systems, environments, etc. are covered. Instead, the purpose of this guide is to provide clear and easy guidelines for running Minikube with KVM on Linux.
- Any Linux you like (in this tutorial we'll use Ubuntu 18.04 LTS, and all the instructions below are applicable to it. If you prefer using a different Linux distribution, please check out the relevant documentation)
libvirtand QEMU-KVM installed and properly configured
- The Kubernetes CLI (
kubectl) for operating the Kubernetes cluster
QEMU/KVM and libvirt installation
NOTE: skip if already installed
Before we proceed, we have to verify if our host can run KVM-based virtual machines. This can be easily checked using the kvm-ok tool, available on Ubuntu.
sudo apt install cpu-checker && sudo kvm-ok
If you receive the following output after running
kvm-ok, you can use KVM on your machine (otherwise, please check out your configuration):
$ sudo kvm-ok INFO: /dev/kvm exists KVM acceleration can be used
Now let's install KVM and libvirt and add our current user to the
libvirt group to grant sufficient permissions:
sudo apt install libvirt-clients libvirt-daemon-system qemu-kvm \ && sudo usermod -a -G libvirt $(whoami) \ && newgrp libvirt
After installing libvirt, you may verify the host validity to run the virtual machines with
virt-host-validate tool, which is a part of libvirt.
kubectl (Kubernetes CLI) installation
NOTE: skip if already installed
In order to manage the Kubernetes cluster, we need to install kubectl, the Kubernetes CLI tool.
The recommended way to install it on Linux is to download the pre-built binary and move it to a directory under the
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl \ && sudo install kubectl /usr/local/bin && rm kubectl
Alternatively, kubectl can be installed with a big variety of different methods (eg. as a .deb or snap package - check out the kubectl documentation to find the best one for you).
Minikube KVM driver installation
A VM driver is an essential requirement for local deployment of Minikube. As we've chosen to use KVM as the Minikube driver in this tutorial, let's install the KVM driver with the following command:
curl -LO https://storage.googleapis.com/minikube/releases/latest/docker-machine-driver-kvm2 \ && sudo install docker-machine-driver-kvm2 /usr/local/bin/ && rm docker-machine-driver-kvm2
Now let's install Minikube itself:
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 \ && sudo install minikube-linux-amd64 /usr/local/bin/minikube && rm minikube-linux-amd64
Verify the Minikube installation
Before we proceed, we need to verify that Minikube is correctly installed. The simplest way to do this is to check Minikube’s status.
To use the KVM2 driver:
Now let's run the local Kubernetes cluster with Minikube and KVM:
minikube start --vm-driver kvm2
Set KVM2 as a default VM driver for Minikube
If KVM is used as the single driver for Minikube on our machine, it's more convenient to set it as a default driver and run Minikube with fewer command-line arguments. The following command sets the KVM driver as the default:
minikube config set vm-driver kvm2
So now let's run Minikube as usual:
Verify the Kubernetes installation
Let's check if the Kubernetes cluster is up and running:
kubectl get nodes
Now let's run a simple sample app (nginx in our case):
kubectl create deployment nginx --image=nginx
Let’s also check that the Kubernetes pods are correctly provisioned:
kubectl get pods
At this point, a Kubernetes cluster with Minikube and KVM is adequately set up and configured on your local machine.
To proceed, you may check out the Kubernetes tutorials on the project website:
It’s also worth checking out the "Introduction to Kubernetes" course by The Linux Foundation/Cloud Native Computing Foundation, available for free on EDX: