-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

The Kubernetes Workshop
By :

Had you asked the question, "How do you easily install Kubernetes?" three years ago, it would have been hard to give a compelling answer. Embarrassing, but true. Kubernetes is a sophisticated system, and getting it installed and managing it well isn't an easy task.
However, as the Kubernetes community has expanded and matured, more and more user-friendly tools have emerged. As of today, based on your requirements, there are a lot of options to choose from:
We will use Minikube extensively throughout this book as a convenient learning environment. But before we proceed to the installation process, let's take a closer look at Minikube itself.
Minikube is a tool that can be used to set up a single-node cluster, and it provides handy commands and parameters to configure the cluster. It primarily aims to provide a local testing environment. It packs a VM containing all the core components of Kubernetes that get installed onto your host machine, all at once. This allows it to support any operating system, as long as there is a virtualization tool (also known as a Hypervisor) pre-installed. The following are the most common Hypervisors supported by Minikube:
Regarding the required hardware resources, the minimum requirement is 2 GB RAM and any dual-core CPU that supports virtualization (Intel VT or AMD-V), but you will, of course, need a more powerful machine if you are trying out heavier workloads.
Just like any other modern software, Kubernetes provides a handy command-line client called kubectl that allows users to interact with the cluster conveniently. In the next exercise, we will set up Minikube and use some basic kubectl commands. We will go into more detail about kubectl in the next chapter.
In this exercise, we will use Ubuntu 20.04 as the base operating system to install Minikube, using which we can start a single-node Kubernetes cluster easily. Once the Kubernetes cluster has been set up, you should be able to check its status and use kubectl
to interact with it:
Note
Since this exercise deals with software installations, you will need to be logged in as root/superuser. A simple way to switch to being a root user is to run the following command: sudo su -
.
In step 9 of this exercise, we will create a regular user and then switch back to it.
which VirtualBox
You should see the following output:
/usr/bin/VirtualBox
If VirtualBox has been successfully installed, the which
command should show the path of the executable, as shown in the preceding screenshot. If not, then please ensure that you have installed VirtualBox as per the instructions provided in the Preface.
curl -Lo minikube https://github.com/kubernetes/minikube/releases/download/<version>/minikube-<ostype-arch> && chmod +x minikube
In this command, <version>
should be replaced with a specific version, such as v1.5.2
(which is the version we will use in this chapter) or the latest
. Depending on your host operating system, <ostype-arch>
should be replaced with linux-amd64
(for Ubuntu) or darwin-amd64
(for macOS).
Note
To ensure compatibility with the commands provided in this book, we recommend that you install Minikube version v1.5.2
.
You should see the following output:
Figure 2.1: Downloading the Minikube binary
The preceding command contains two parts: the first command, curl
, downloads the Minikube binary, while the second command, chmod
, changes the permission to make it executable.
/usr/local/bin
) so that we can directly run Minikube, regardless of which directory the command is run in:mv minikube /usr/local/bin
When executed successfully, the move (mv
) command does not give a response in the terminal.
which minikube
You should see the following output:
/usr/local/bin/minikube
Note
If the which minikube
command doesn't give you the expected result, you may need to explicitly add /usr/local/bin
to your system path by running export PATH=$PATH:/usr/local/bin
.
minikube version
You should see the following output:
minikube version: v1.5.2 commit: 792dbf92a1de583fcee76f8791cff12e0c9440ad-dirty
v1.16.2
(so that it's compatible with the version of Kubernetes that our setup of Minikube will create later) and make it executable by using the following command:curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.16.2/bin/<ostype>/amd64/kubectl && chmod +x kubectl
As mentioned earlier, <ostype>
should be replaced with linux
(for Ubuntu) or darwin
(for macOS).
You should see the following output:
Figure 2.2: Downloading the kubectl binary
mv kubectl /usr/local/bin
which kubectl
You should see the following response:
/usr/local/bin/kubectl
root
user, let's create a regular user called k8suser
by running the following command:useradd k8suser
Enter your desired password when you are prompted for it. You will also be prompted to enter other details, such as your full name. You may choose to skip those details by simply pressing Enter. You should see an output similar to the following:
Figure 2.3: Creating a new Linux user
Enter Y
and hit Enter to confirm the final prompt for creating a user, as shown at the end of the previous screenshot.
root
to k8suser
:su - k8suser
You should see the following output:
root@ubuntu:~# su – k8suser k8suser@ubuntu:~$
minikube start
:minikube start --kubernetes-version=v1.16.2
Note
If you want to manage multiple clusters, Minikube provides a --profile <profile name>
parameter to each cluster.
It will take a few minutes to download the VM images and get everything set up. After Minikube has started up successfully, you should see a response that looks similar to the following:
Figure 2.4: Minikube first startup
As we mentioned earlier, Minikube starts up a VM instance with all the components of Kubernetes inside it. By default, it uses VirtualBox, and you can use the --vm-driver
flag to specify a particular hypervisor driver (such as hyperkit
for macOS). Minikube also provides the --kubernetes-version
flag so you can specify the Kubernetes version you want to use. If not specified, it will use the latest version that was available when the Minikube release was finalized. In this chapter, to ensure compatibility of the Kubernetes version with the kubectl version, we have specified Kubernetes version v1.16.2
explicitly.
The following commands should help establish that the Kubernetes cluster that was started by Minikube is running properly.
minikube status
You should see the following response:
host: Running kubelet: Running apiserver: Running kubeconfig: Configured
kubectl version --short
You should see the following response:
Client Version: v1.16.2 Server Version: v1.16.2
kubectl get node
You should see a response similar to the following:
NAME STATUS ROLES AGE VERSION minikube Ready master 2m41s v1.16.2
After finishing this exercise, you should have Minikube set up with a single-node Kubernetes cluster. In the next section, we will enter the Minikube VM to take a look at how the cluster is composed and the various components of Kubernetes that make it work.