Kubernetes hello minikube on Fedora 25

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.


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

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/

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/

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

Create a cluster

minikube start --vm-driver=kvm

Set context and view info

kubectl config use-context minikube
kubectl cluster-info

View the vm minikube created

sudo virsh list --all
sudo virsh dumpxml minikube

View the files minikube wrote

tree ~/.minikube/

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.

Create a hello app in Golang

mkdir hello && cd hello

Then create main.go with the following contents:

package main

import (

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

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

Compile it and verify it has no dependencies

CGO_ENABLED=0 go build
ldd hello

Create a docker container

Create a Dockerfile with the following contents:

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

Build and test the container

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

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

Create a service and test it

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

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

Delete the service

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

Stop directing docker at the vm

eval $(minikube docker-env -u)

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}