DevOps

How to Get Started with Minikube

A Kubernetes cluster always consists of multiple servers. However, Minikube was developed so that you don't have to set up a server farm to learn K8s and can be able to test and play without much effort.

 

In this post, we will introduce you to the Minikube tool, which only requires one computer. However, it is ideal if you have multiple computers available that you can use to build a small test cluster.

 

Minikube simulates a Kubernetes cluster on your local computer using a container or VM. This works very well for experimentation purposes, but in the end it is only a simulation of a real distributed Kubernetes setup. The performance and size of the cluster are limited to your computer, but for almost all the exercises in this book, Minikube will suffice.

 

In the following sections, we will guide you through the installation for the different operating systems and show you how to get Minikube up and running with Docker.

 

An installed Docker engine is required for the installation. Use Docker Desktop for that. You can find the installation instructions at the following address: http://s-prs.co/v596403.

 

If you want to start Minikube with a VM manager, you should take a look at the installation instructions available at http://s-prs.co/v596404.

 

Important Note for Company Computers: If you want to carry out the following instructions with a device that is managed by your employer, this can lead to problems. Most workstations have restricted rights or certain security policies that prevent the instructions provided here from working. We recommend that you use a computer that is not managed by a company and on which you have full admin rights. And of course, it makes sense perhaps not to use your own workstation with important data for such experiments.

 

If you still want to use a company computer, then contact your company's administrator if you have any problems.

 

If you use your company computer, you may need a license for Docker Desktop. Please check this beforehand.

 

Minikube on macOS

There are different ways to install Minikube for Mac. It is a command line tool and is also installed via the terminal. We’ll show you two options, the first of which is the simplest.

Installation Via the Homebrew Package Manager

The easiest way is to use a package manager called Homebrew. It makes installing software quick and easy, because where you would normally have to download, install, and configure packages manually, Homebrew does it for you. If you have not yet installed a package manager for your Mac, we recommend that you do so now.

 

Open the terminal and run the following command:

 

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/

HEAD/install.sh)"

 

You will then be asked to enter your password and confirm the installation by pressing (Enter). After the installation has been completed, you can use the package manager with the brew command.

 

You can now carry out the installation of Minikube. To do this, enter the following command in your terminal:

 

brew install minikube

 

This will download and install Minikube from Homebrew. Once the installation is complete, you can use the minikube version command to test whether the software has been installed and if it is ready. The command line should then output the corresponding version of Minikube. In this case, the output looks as follows:

 

minikube version

minikube version: v1.30.1

commit: 08896fd1dc362c097c925146c4a0d0dac715ace0

 

Note that you may have a newer version depending on when you read this post.

Manual Installation

If you do not wish to install the Homebrew package manager, you can also install Minikube manually. First, you need to download the installation files that match your processor architecture. The following command is suitable for Macs with Intel processors:

 

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikubedarwin-

amd64

 

Then, install Minikube. You need to have admin rights for this step:

 

sudo install minikube-darwin-amd64 /usr/local/bin/minikube

 

Run the following commands if your Mac has an Apple processor:

 

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikubedarwin-

arm64

sudo install minikube-darwin-arm64 /usr/local/bin/minikube

 

You should now also be able to test whether the installation was successful using the minikube version command.

 

Minikube on Linux

In the following sections, we will address the most common installations for Linux. You can find a complete selection at http://s-prs.co/v596405.

Installation on Linux with x86-64 Architecture

If you have an x86-64 architecture, you can perform the installation in three ways, depending on which distribution you are using. A Minikube package may also be available in a repository for easy installation.

 

If you need a Debian package, the following two commands will download the installation file and install Minikube:

 

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_

latest_amd64.deb

sudo dpkg -i minikube_latest_amd64.deb

 

If you use an RPM distribution, this will get you there:

 

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikubelatest.

x86_64.rpm

sudo rpm -Uvh minikube-latest.x86_64.rpm

 

You can also download and install the binary file directly:

 

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikubelinux-

amd64

sudo install minikube-linux-amd64 /usr/local/bin/minikube

Installation on Linux with ARM64 Architecture

There are also three ways to install the ARM64 architecture.

 

With a Debian package:

 

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_

latest_arm64.deb

sudo dpkg -i minikube_latest_arm64.deb

 

With an RPM package:

 

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikubelatest.

aarch64.rpm

sudo rpm -Uvh minikube-latest.aarch64.rpm

 

Downloading the binary file:

 

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikubelinux-

arm64

sudo install minikube-linux-arm64 /usr/local/bin/minikube

 

Minikube on Windows

Three options are available for the installation on Windows. If you have already installed the Chocolatey package manager or Windows Package Manager, you can skip to the corresponding instructions. The installation via a package manager is much easier, but you must install one first.

 

Package Manager for Windows: If you want to use a package manager and have installed Windows 10 or Windows 11, you should take a look at Windows Package Manager. This significantly simplifies the installation of programs such as Minikube. You can find detailed instructions from Microsoft at the following link: http://s-prs.co/v596406.

Installation Using Chocolatey

The installation using the Chocolatey package manager is very simple. You need to run the following command in your PowerShell:

 

choco install minikube

Installation Using the Windows Package Manager

The installation is also easy via Windows Package Manager. Just run the following command

in PowerShell:

 

winget install minikube

Manual Installation

The commands for a manual installation are somewhat more complex. We recommend that you copy the commands from the Minikube installation page. To do this, go to http://s-prs.co/v596405 and select the Windows operating system and .exe download in Installer Type.

 

Then you can copy the following command and paste it into the PowerShell to download Minikube:

 

New-Item -Path 'c:\' -Name 'minikube' -ItemType Directory

   -Force Invoke-WebRequest -OutFile 'c:\minikube\minikube.exe'

   -Uri 'https://github.com/kubernetes/minikube/releases/latest/download/

                       minikube-windows-amd64.exe'

   -UseBasicParsing

 

For Minikube to be executable in PowerShell, the program must be entered in the PATH variable. The following command takes care of this (note that this command requires admin rights). Then you must start PowerShell as an administrator:

 

$oldPath = [Environment]::GetEnvironmentVariable('Path',

                       [EnvironmentVariableTarget]::Machine)

if ($oldPath.Split(';') -inotcontains 'C:\minikube'){

   [Environment]::SetEnvironmentVariable('Path', $('{0};C:\minikube' -f

                      $oldPath), [EnvironmentVariableTarget]::Machine)

}

 

You can now close and reopen PowerShell and use the minikube version command to test whether the software has been installed and if it is ready to use. The command line should then output the corresponding version of Minikube. In our case, the output looks as follows:

 

minikube version

minikube version: v1.30.1

commit: 08896fd1dc362c097c925146c4a0d0dac715ace0

 

Note that you may have a newer version depending on when you read this post.

 

Launching Minikube

Once you have installed Minikube, you can easily launch it from your command line. To do this, you want to run the following command:

 

minikube start

 

Minikube then creates some activity and documents all processes in logs, which will be output directly. Because it is based on Docker, Minikube will download the latest container first. Minikube also indicates which version of Kubernetes is being started. You will then see information about additional add-ons that are not relevant for the time being. You do not need to make a note of any of this as we will come back to it in due course.

 

You now have a Kubernetes cluster running in a Docker container on your computer.

 

Controlling Minikube

Before we get to the interaction with the Kubernetes cluster, we would like to briefly explain how you can use Minikube. We have already executed the minikube start command. You have used this command to start the cluster in a Docker container.

 

If you want to pause the containers running in the cluster, you can use the minikube pause and minikube unpause commands. These will both pause your containers and stop the system containers that make up Kubernetes. You should use these commands when you are not using your test cluster as doing so saves resources.

 

You can also stop Minikube by running minikube stop. This stops the Minikube container completely. However, the state remains the same. This command is good to run before you shut down your computer. The same container is restarted via the start command and continues in the same state as before it was stopped.

 

Finally, you can use the minikube delete command to delete your cluster entirely. This command is particularly useful if you need a fresh cluster and want to get rid of your old tests.

 

These commands enable you to control Minikube.

 

Possible Errors when Starting Minikube

You may encounter two small errors when you start Minikube. Let's take a brief look at how this happens and how you can solve it if you receive the corresponding error message.

 

If you run the minikube start command, the following error may occur:

 

Exiting due to PROVIDER_DOCKER_NOT_RUNNING:

"docker version --format -:" exit status 1: Cannot connect to the

Docker daemon at unix:///Users/kevinwelter/.docker/run/docker.sock.

Is the docker daemon running?

 

This error may look slightly different on Windows, but the issue is the same, and the hint is already in the error message. The Is the docker daemon running? message indicates that Docker Desktop is not running. Start Docker and try to execute the command again. Minikube should now start. This error can occur especially after restarting your computer if you have not activated Docker via autostart.

 

Another error message after you run the minikube start command might look something like this:

 

command not found: minikube

 

This indicates that the command line interface tool cannot be found. If you have carried out the installation steps given earlier correctly, then try to restart the command line. In some cases, especially when installing manually, the tool may not yet be activated in the path.

 

Container Registry of Minikube

Here we will show you how to install and use the Minikube container registry add-on.

 

Minikube comes with some add-ons that allow you to build a nice and simple Kubernetes test environment without the need for external dependencies.

 

You can use the minikube addons list command to get an overview of the extensions. We won't need them all, but perhaps you will come back to them at some point.

 

The most important add-on is the container registry. If you want to develop your own containers and deploy them in Kubernetes, there is no way around a registry, as Kubernetes only retrieves the images required for the containers from there. In production environments, you naturally need a professional registry to manage and securely store your images. For our test cluster, however, such an effort is excessive and we can revert to the useful add-on.

 

The add-on can be activated using the minikube addons enable registry command. Now the next part is important! This is because a port that you should use is displayed as the output. You do not need this!

 

Instead, you want to run the eval $(minikube docker-env) command on Linux or on a Mac. In PowerShell, the command is minikube -p minikube docker-env | Invoke-Expression.

 

This call makes sure that you use the Docker daemon from Minikube. You can then also access the registry via the default port 5000.

 

Note: You must run the eval $(minikube docker-env) command with every new command line; otherwise, you will not be able to access the registry. If you don't want to think about it every time, you can also write the command in your .bashrc or .zshrc, depending on the command line, so that it gets always executed. You can enter the command in your profile in PowerShell. Note that you then use the Docker host from Minikube.

 

Now let's test whether you can store containers in the registry. Use the following oneline Dockerfile for this purpose:

 

FROM nginx

 

Create this as a Dockerfile and run the docker build -t localhost:5000/test-nginx . command. Your own Nginx image will now be built and tagged with the name of the registry. Then you can store the image in the registry using the docker push localhost: 5000/test-nginx command. From now on, Kubernetes can access the image with the image name and download it.

 

Important Convention for the Image Name: If you are familiar with Docker, then you will certainly also know the naming conventions for images. You must start the name using the URL of the registry, as this is the only way Docker can also assign the image to a registry and store it there in the event of a push. You can of course continue to name the images locally as you wish.

 

Editor’s note: This post has been adapted from a section of the book Kubernetes: Practical Guide for Developers and DevOps Teams by Kevin Welter.

Recommendation

Kubernetes
Kubernetes

Unravel the complexities of Kubernetes with this hands-on guide! Start with an introduction to Kubernetes architecture and components such as nodes, Minikube, and kubectl commands. Follow tutorials to set up your first clusters and pods, and then dive into more advanced concepts like DaemonSets, batch jobs, and custom resource definitions. Perform resource management, set up autoscaling, deploy applications with Helm, and more!

Learn More
Rheinwerk Computing
by Rheinwerk Computing

Rheinwerk Computing is an imprint of Rheinwerk Publishing and publishes books by leading experts in the fields of programming, administration, security, analytics, and more.

Comments