Learn how to install Minikube and kubectl on Mac, Windows, and Linux, in this guest tutorial by Jaroslaw Krochmalski, the author of Docker and Kubernetes for Java Developers.
The Minikube tool source code with all the documentation is available at GitHub at https://github.com/kubernetes/minikube
Installing on Mac
The following sequence of commands will download the minikube binary, set the executable flag and copy it to the /usr/local/bin folder, which will make it available in the macOS shell:
$ curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.12.2/minikube-darwin-amd64 $ chmod +x minikube $ sudo mv minikube /usr/local/bin/
Alternatively, if you use Homebrew package manager (available freely at https://brew.sh), which is, by the way, very handy and recommended, you can just install minikube by typing:
$ brew cask install minikube
Installing on Windows
Minikube for Windows is again a single executable file. You can always find the newest version on the Minikube’s site, at https://github.com/kubernetes/minikube. You just need to download the latest executable, rename it minikube.exe, and place it in your system path to access it from the command line.
Installing on Linux
The installation process on Linux is identical to the macOS one. The only difference is in the executable’s name. The following command will download the latest Minikube release. Set the executable bit and move it to the /usr/local/bin directory:
$ curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
That’s all, a single Minikube and Docker is all you need to start the local cluster. It’s time to bring it to life.
Starting up the local Kubernetes cluster
You’ll now use the local Kubernetes cluster provided by minikube. Start your cluster with the following:
$ minikube start
Minikube works on its own virtual machine. Depending on your host OS, you can choose between several virtualization drivers. The currently supported ones are virtualbox, vmwarefusion, xhyve, hyperv, and kvm (Kernel-based virtual machine). The default VM driver is virtual box, which you can override. This is the macOS startup command line using xhyve:
$ minikube start --vm-driver=xhyve
When starting Minikube for the first time, you will see it downloading the Minikube ISO, so the process will take a little longer. This is, however, a one-time action. The Minikube configuration will be saved in the .minikube folder in your home directory, for example ~/.minikube on Linux or macOS. On the first run, Minikube will also configure the kubectl command line tool (more on it in a short while) to use the local minikube cluster. This setting is called a kubectl context. It determines the cluster that kubectl will interact with. All available contexts are present in the ~/.kube/config file.
Since the cluster is running now and you have the dashboard add-on enabled by default, you can take a look at the (still empty) Kubernetes dashboard with the following command:
$ minikube dashboard
It will open your default browser with the URL of the cluster’s dashboard:
As you can see, the dashboard is empty now. If you browse to the Namespaces menu, you will notice that Minikube creates some namespaces. Parts of the Minikube installation, such as DNS or the Dashboard, also run on the cluster itself with separate namespaces like kube-public and kube-system.
Feel free to browse the menus and sections; so far, no harm can be done as it’s a local development cluster running nothing at the moment.
Of course, having the cluster running empty is quite useless, so you need a tool to manage it. While we can run almost everything using the dashboard, it’s a lot more convenient to have a command line tool for it. kubectl controls the Kubernetes cluster. You can use the kubectl command line tool heavily to deploy, schedule, and scale your applications and microservices. The tool comes as a self-contained binary for Mac, Linux, and Windows. In the next section you will find installation instructions for different platforms.
kubectl is available for all major platforms. This tutorial will cover kubectl installation on macOS, Windows, and Linux.
Installing on Mac
The following sequences of command will download the kubectl binary. Set the executable flag and copy it to the /usr/local/bin folder, which will make it available in the macOS shell:
$ curl -O https://storage.googleapis.com/kubernetes-release/release/v1.5.2/bin/darwin/amd64/kubectl $ chmod +x kubectl $ sudo cp kubectl /usr/local/bin
Homebrew provides the most convenient way to install kubectl and keep it up to date. To install, use this command:
$ brew install kubectl
To update, use the following command:
$ brew upgrade kubectl
Installing on Windows
You can find the list of Windows kubectl releases on GitHub at https://github.com/eirslett/kubectl-windows/releases. Similar to Minikube, kubectl is just a single .exe file: https://github.com/eirslett/kubectl-windows/releases/download/v1.6.3/kubectl.exe. You will need to download the exe file and place it on your system path in order to access it in the command line.
Installing on Linux
The installation process is, again, very similar to the macOS. The following commands will fetch the kubectl binary, give it an executable flag, and then move it to /usr/local/bin to make it available in the shell:
$ curl -O https://storage.googleapis.com/kubernetes-release/release/v1.5.2/bin/linux/amd64/kubectl $ chmod +x kubectl $ sudo cp kubectl /usr/local/bin/kubectl
To verify if your local cluster is up and running and kubectl is properly configured, execute the following command:
$ kubectl cluster-info
In the output, you will be given basic information about the cluster, which includes its IP address and Minikube add-ons:
To list the nodes you have running in the cluster, execute the get nodes command:
$ kubectl get nodes
Of course, this is just a single node cluster, so there is no surprise in the output of the above command:
Your cluster is now up and running.
If you found this tutorial interesting and want to learn more about Docker and Kubernetes, you can explore Docker and Kubernetes for Java Developers, an easy-to-follow practical guide that will help Java developers develop, deploy, and manage Java applications efficiently.