This is a quick Fedora Linux specific version of the upstream Hello Minikube guide. It uses Golang as the hello world application and tries to call out a few useful things along the way.

Permalink Dependencies

You’ll need golang, kvm and libvirt along with proper group membership:

sudo dnf install golang libvirt-daemon-kvm
sudo usermod -a -G libvirt $(whoami)
newgrp libvirt

Permalink Install minikube itself

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

Reference: https://kubernetes.io/docs/tutorials/stateless-application/hello-minikube/

Permalink Install kubectl

curl -Lo kubectl \
  https://storage.googleapis.com/kubernetes-release/release/v1.5.3/bin/linux/amd64/kubectl \
  && chmod +x kubectl \
  && sudo mv kubectl /usr/local/bin/

Reference: https://kubernetes.io/docs/tutorials/stateless-application/hello-minikube/

Permalink Install docker-machine-driver-kvm

curl -Lo docker-machine-driver-kvm \
  https://github.com/dhiltgen/docker-machine-kvm/releases/download/v0.7.0/docker-machine-driver-kvm \
  && chmod +x docker-machine-driver-kvm \
  && sudo mv docker-machine-driver-kvm /usr/local/bin

Reference: https://github.com/kubernetes/minikube/blob/master/DRIVERS.md#kvm-driver

Permalink Create a cluster

minikube start --vm-driver=kvm

Permalink Set context and view info

kubectl config use-context minikube
kubectl cluster-info

Permalink View the vm minikube created

sudo virsh list --all
sudo virsh dumpxml minikube

Permalink View the files minikube wrote

tree ~/.minikube/

Permalink Prepare to build and deploy a local container

eval $(minikube docker-env)

After running this command docker will talk to the docker daemon inside the Minikube vm. Failing to run this command will result in Kubernetes being unable to fetch the container: ErrImagePull. See the end of this document on how to “undo” this.

Permalink Create a hello app in Golang

mkdir hello && cd hello

Then create main.go with the following contents:

package main

import (
	"fmt"
	"log"
	"net/http"
)

func indexHandler(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Hello world")
}

func main() {
	http.HandleFunc("/", indexHandler)
	log.Fatal(http.ListenAndServe(":8080", nil))
}

Permalink Compile it and verify it has no dependencies

CGO_ENABLED=0 go build
ldd hello

Permalink Create a docker container

Create a Dockerfile with the following contents:

FROM scratch
EXPOSE 8080
COPY ./hello /hello
CMD ["/hello"]

Permalink Build and test the container

docker build -t hello-golang:v1 .
docker run --rm hello-golang:v1

Permalink Deploy the container to kubernetes

kubectl run hello-golang --image=hello-golang:v1 --port=8080
kubectl get deployments
kubectl get pods
kubectl get events
kubectl config view

Permalink Create a service and test it

kubectl expose deployment hello-golang --type=LoadBalancer
kubectl get services
minikube service hello-golang

Permalink Update the service and test it

vim main.go
CGO_ENABLED=0 go build
docker build -t hello-golang:v2 .
kubectl set image deployment/hello-golang hello-golang=hello-golang:v2
minikube service hello-golang

Permalink Delete the service

kubectl delete service hello-golang
kubectl delete deployment hello-golang

Permalink Stop directing docker at the vm

eval $(minikube docker-env -u)

Permalink Delete everything if desired

If you want to remove everything as though never started, you’d do something like this:

sudo virsh shutdown minikube
sudo virsh undefine minikube
rm -rf ~/.minikube

If you want to remove the dependencies as well:

sudo rm /usr/local/bin/{minikube,kubectl,docker-machine-driver-kvm}