Before you begin

In this tutorial will learn how to install Kubernetes locally using minikube. A Linux machine will be required to follow this tutorial.

Install Kubernetes client (kubectl)

Run the following script using sudo to install kubectl for Linux:

#!/bin/bash

set -e

apt-get install curl -y

curl -LO 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

mv ./kubectl /usr/local/bin/kubectl

More information about how to install Kubernetes here.

Install Minikube

Run the following script using sudo to install minikube for Linux:

#!/bin/bash

set -e

apt-get install virtualbox curl -y

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

More information about how to install Minikube here.

Start Minikube

Minikube requires ENV variables to be set. Use the following script to start minikube locally:

#!/bin/bash

export MINIKUBE_WANTUPDATENOTIFICATION=false
export MINIKUBE_WANTREPORTERRORPROMPT=false
export MINIKUBE_HOME=$HOME
export CHANGE_MINIKUBE_NONE_USER=true
mkdir -p $HOME/.kube || true
touch $HOME/.kube/config

export KUBECONFIG=$HOME/.kube/config
minikube start --vm-driver=none


Test Minikube

Once minikube and kubectl binaries are installed we could do some tests. For example run a nginx container:

$ kubectl run nginx --image=docker.io/nginx:latest --port=80
$ kubectl expose deployment hello-minikube --type=NodePort

$ kubectl get deployment
>
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx     1         1         1            1           7m

$ kubectl get pods
>
NAME                     READY     STATUS    RESTARTS   AGE
nginx-2092755988-lzn67   1/1       Running   0          7m

$ kubectl port-forward nginx-2092755988-lzn67 80:80
>
Forwarding from 127.0.0.1:80 -> 80
Forwarding from [::1]:80 -> 80

Nginx will be available at http://127.0.0.1:80.

More information about how to use Minikube here.

Remove test

Finally to delete previous nginx deployment and service and stop minikube:

$ kubectl delete deployment nginx
$ kubectl delete service nginx

$ minikube stop