As Kubernetes seems to have "won" the "battle" for container orchestration this post shows how to get up and running with Kubernetes locally via Minikube and Virtualbox on Mac OS.
Although the installation guide is pretty straight forward and well explained, it is a little "scattered" to a few places over the web. So here is a "linear" walkthrough for v0.24.1
on Mac OS with an already installed Virtualbox (which will host the Minikube virtual machine). The setup is pretty much comparable to Docker Toolbox.
Overview / Downloads
Actually all you need to download is
kubectl
(Kubernetes command-line tool) andMinikube
(which runs a single-node Kubernetes cluster inside a VM, e.g. hosted in Virtualbox).
This post assumes that Virtualbox is already installed (as e.g. by previously using Docker Toolbox
).
Installing kubectl
Sources:
https://kubernetes.io/docs/tasks/tools/install-kubectl/
https://kubernetes.io/docs/reference/generated/kubectl/kubectl/
If you don't care about checksums you can just download the latest release as mentioned in the first link above:
curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/darwin/amd64/kubectl
# where `curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt` expands to e.g. `v1.9.2`
Or if you prefer to check the checksum
you can download v1.9.2
like so:
curl -LO https://dl.k8s.io/v1.9.2/kubernetes-client-darwin-amd64.tar.gz
And compare the output of:
shasum -a 256 kubernetes-client-darwin-amd64.tar.gz
with the checksums listed here.
After that you can extract it and cd
into it:
tar xvf kubernetes-client-darwin-amd64.tar.gz
cd kubernetes/client/bin/
Either way make sure that kubectl
is executable
:
ls -al
chmod +x ./kubectl # for the .tar.gz x is already set
After that kubectl
needs to be in your path
:
sudo mv ./kubectl /usr/local/bin/kubectl
If in the current shell you are neither an administrator or a sudo-privileged user you could also do something like:
mv ./kubectl /Users/Shared
su <admin_user>
sudo mv /Users/Shared/kubectl /usr/local/bin/kubectl
ls -al /usr/local/bin/ # only to check if executable
exit
That's it for the command line tool. However, there are various other ways as well to get kubectl
, e.g. Homebrew
or Google Cloud SDK
.
Installing minikube
Sources:
https://kubernetes.io/docs/getting-started-guides/minikube/
https://kubernetes.io/docs/tasks/tools/install-minikube/
https://github.com/kubernetes/minikube/releases
https://github.com/kubernetes/minikube
Second and last part for the basic setup is to download and run minikube
:
Minikube is a tool that makes it easy to run Kubernetes locally. Minikube runs a single-node Kubernetes cluster inside a VM on your laptop for users looking to try out Kubernetes or develop with it day-to-day. Source
curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.24.1/minikube-darwin-amd64
shasum -a 256 minikube
Checksums again can be found here.
Make it executable
as well:
chmod +x minikube
And also as before minikube
needs to be in your path
sudo mv minikube /usr/local/bin/
Same as above (if not an administrator nor a sudo-privileged user):
mv ./minikube /Users/Shared
su <admin_user>
sudo mv /Users/Shared/minikube /usr/local/bin/minikube
ls -al /usr/local/bin/ # only to check if executable
exit
Getting up and running
Sources:
https://github.com/kubernetes/minikube
https://github.com/kubernetes/minikube/blob/v0.24.1/README.md
https://github.com/kubernetes/minikube/blob/master/docs/README.md
If not using virtualbox
you need to specify --vm-driver
as described here. But if using virtualbox
you can just do:
minikube start
The log
looked like the following and especially after having downloaded the Minikube ISO it took some time before it continued:
Starting local Kubernetes v1.8.0 cluster...
Starting VM...
Downloading Minikube ISO
...
# Here it took some time ...
# But you can check the Mac OS Activity Monitor for a "vBox Headless" process or in Virtualbox UI if a new machine "minikube" is running
...
Getting VM IP address...
Moving files into cluster...
Downloading localkube binary
...
Connecting to cluster...
Setting up kubeconfig...
Starting cluster components...
Kubectl is now configured to use the cluster.
Loading cached images from config file.
After that your local mini Kubernetes cluster is up and running and you can start your first deployment (most of the the following examples are taken from here):
kubectl run hello-minikube --image=gcr.io/google_containers/echoserver:1.4 --port=8080
kubectl expose deployment hello-minikube --type=NodePort
You can now interact with your minikube cluster either via cli
(minikube
or kubectl
) ...
kubectl get pod
curl $(minikube service hello-minikube --url)
minikube service -n default --url hello-minikube # prints the url
minikube service -n default hello-minikube # opens a browser window
minikube ip
minikube # for general usage
minikube service --help # for usage of a certain command, here service
minikube service list # for a list of all services
minikube service -n kube-system list # for a list of services within the namespace kube-system
kubectl delete service hello-minikube
kubectl delete deployment hello-minikube
minikube stop
... or in the Kubernetes
browser-based dashboard
:
minikube dashboard
# opens dashboard in browser
# http://<minikube_ip>:30000
Advanced topics can be found here, e.g. debugging, Environment Variables, or Host Folder Mounting.
Have fun with your new docker conductor for your container orchestra.
Further Information
Kubernetes:
https://kubernetes.io
https://github.com/kubernetes/kubernetes/releases
https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG-1.9.md#downloads-for-v192
kubectl:
https://kubernetes.io/docs/tasks/tools/install-kubectl/
https://kubernetes.io/docs/reference/generated/kubectl/kubectl/
Minikube:
https://github.com/kubernetes/minikube
https://kubernetes.io/docs/getting-started-guides/minikube/
https://kubernetes.io/docs/tasks/tools/install-minikube/
https://github.com/kubernetes/minikube/blob/v0.24.1/README.md
https://github.com/kubernetes/minikube/blob/master/docs/README.md