Kubernetes is extensive platform for managing container clusters, coming from Google. Like most server software from Google, Kubernetes excels in scalability but it might be challenging to use it for local deployment on a say laptop . So for this example I will use my production laptop which is running Fedora 24, but you can use any linux distro as the actual containers are run in VirtualBox. We are going to use two methods to install Kubernetes, the deprecated vagrant method and recommended Minikube method. For both methods we will use VirtualBox, but for Vagrant it is also possible to deploy on bare metal by simply switching provider from "virtualbox" to say "ubuntu" or "centos".
- You need a linux distro with Virtual box installed. (5.1 is not supported yet, I had to downgrade to 5.0)
- You also need Vagrant installed, sudo dnf install vagrant will do it on fedora.
After setting up prerequisites, we run the script to install Kubernetes inside VirtualBox
export KUBERNETES_PROVIDER=vagrant; wget -q -O - https://get.k8s.io | bash
This script will download all needed stuff and create default cluster for you.
It might run little longer so be patient. After it is done it will display long message with the ip addresses of the containers it created. You log into master by following command
ssh firstname.lastname@example.org -p 2222
password is "vagrant", off course without quotes. The root password is also vagrant. So now you have fully functional Kubernetes cluster on your local machine. When you shutdown the cluster and want it back up, you first cd into ~/kubernetes directory in your /home, and then while inside you execute following commands:
And your cluster will be up again.
This method is easy enough but trouble is that it is deprecated. Support for Virtual Box 5.1 might never come, so we will also do another method with minikube
- You need virtual box
- You need to install kubectl to your host machine
We assume that you already know how to install virtual box, so here is how to install kubectl
curl -Lo kubectl http://storage.googleapis.com/kubernetes-release/release/v1.3.6/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
Then install minikube:
curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.8.0/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
Then we start the cluster:
After that you have a minikube master start, and you can use kubectl and minikube commands to administer your minikube cluster.
[miki@x550jk ~]$ kubectl get nodes
NAME STATUS AGE
minikubevm Ready 12m
If you want to access kubernetes dashboard, just type
It will open the dashboard in a browser tab.
Best things about minikube is that you don't need to ssh into your master VM, you just issue kubectl commands from your host. The kubectl can be used to administer both your minikube local install as well as remote cluster that you might want to build after you get familiar with Kubernetes on your machine. So to switch between clusters managed, there is the concept of contexts. For now, context is set automatically on local minikube, but if need to switch it back to minikube after using with some other install (vagrant, your remote server, etc) use this command:
kubectl config use-context minikube
If you need to ssh into vm for some reason, you can do it with
Here we have two methods to get Kubernetes running locally, for purposes of learning, development and testing. Minikube is preferred and recommended method so we will in next article use minikube to set up applications. After you get familiar with Kubernetes, you will want to run it on remote servers, so we will talk about that in some of future articles. If you are to can't wait for next articles and want to delve into Kubernetes right now, official site has pretty good docs for you. Thank you for reading, that is all for this article.
You might also like
Category: LINUX HOWTO