This article contains the steps to setup Kubernetes (K8s) minikube and kubectl on an Ubuntu instance. The Ubuntu version used is 16.04.3 that is running in a VM. The official minikube GitHub repository will have the steps for various environments. There are a few tweaks needed. The below steps gets straight down to business.

Install minikube

Minikube contains a command-line interface (CLI) tool to allow us to run a local Kubernetes instance. This provisions a single-node cluster. It is a fun way to dip your toes into the Kubernetes world.

Command for minikube on Linux to a directory that a normal user can run:

curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
Verify minikube is installed

Type minikube in the terminal and it will list commands that can be used.

Install kubectl

Kubectl also contains a CLI. It is a control used to interact with and manage Kubernetes.

Command for kubectl on Linux to a directory that a normal user can run:

curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
Verify kubectl is installed

Type kubectl in the terminal and it will list commands that can be used.

Verify minikube is running with kubectl configured

Run the following command to check the minikube status:

sudo minikube status

Initially it will not have any state (if later minikube is stopped it will be in a ‘Stopped’ state):

minikube:
cluster: 
kubectl:

Start minikube:

sudo minikube start --vm-driver=virtualbox

# Example return output:
Starting local Kubernetes v1.8.0 cluster...
Starting VM...
Getting VM IP address...
Moving files into cluster...
Setting up certs...
Connecting to cluster...
Setting up kubeconfig...
Starting cluster components...
Kubectl is now configured to use the cluster.

Note: if there are any issues e.g. E1202 3086 start.go:156] Error starting host: Error creating host: Error executing step: Running precreate checks.
: VBoxManage not found. Make sure VirtualBox is installed and VBoxManage is in the path

Try the following:

# Default start. That should work else for Linux only support use "minikube start --vm-driver=none" - quickstart section
sudo minikube start

sudo minikube stop

sudo minikube start --vm-driver=virtualbox

Re-run the minikube status command to see the updated state:

minikube: Running
cluster: Running
kubectl: Correctly Configured: pointing to minikube-vm at 127.0.0.1

Notice that minikube and cluster is running and that kubectl is correctly configured.

Docker using the minikube host

There is no need to push Docker images to a registry especially if we are trying to test locally. If the code is rebuilt and tagged in Docker it should already have pulled the image from before and will reuse this locally unless the latest version is specified.

If there are issues with this then do the following. Much the same as we can set docker to run against a particular machine using docker-machine env. We can also set minikube to use the Docker daemon.

Use minikube host
eval $(minikube docker-env)
Revert minikube host setting
sudo eval $(minikube docker-env)
Building images
docker build -t {give_it_a_name} .

That concludes the K8s minikube and kubectl on an Ubuntu VM. There will be more posts to explore the Kubernetes world.

 

Leave a comment

Your email address will not be published. Required fields are marked *