Kubernetes Hello Minikube Fedora 27
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.
This is a follow up to: Kubernetes Hello Minikube Fedora 25
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://github.com/kubernetes/minikube/releases/download/v0.25.2/minikube-linux-amd64 \
&& chmod +x minikube \
&& sudo mv minikube /usr/local/bin/
Permalink
Install kubectl
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.9.6/bin/linux/amd64/kubectl \
&& chmod +x kubectl \
&& sudo mv kubectl /usr/local/bin/
Permalink
Install docker-machine-driver-kvm2
curl -LO https://github.com/kubernetes/minikube/releases/download/v0.25.2/docker-machine-driver-kvm2 \
&& chmod +x docker-machine-driver-kvm2 \
&& sudo mv docker-machine-driver-kvm2 /usr/local/bin
Reference: https://github.com/kubernetes/minikube/blob/master/docs/drivers.md#kvm2-driver
Permalink
Create a cluster
minikube start --vm-driver=kvm2
Permalink
View cluster config and info
kubectl config view
kubectl cluster-info
kubectl get pods || echo "fail"
Permalink
View the vm minikube created
sudo virsh list --all
sudo virsh dumpxml minikube
Permalink
View the files minikube wrote
tree ~/.minikube/
Permalink
Run an upstream provided test container
kubectl run hello-minikube --image=gcr.io/google_containers/echoserver:1.4 --port=8080
kubectl expose deployment hello-minikube --type=NodePort
kubectl get pod
curl $(minikube service hello-minikube --url)
kubectl delete deployment hello-minikube
kubectl get pod
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 minikube (the vm)
minikube stop
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 undefine minikube
rm -rf ~/.minikube
rm -rf ~/.kube
If you want to remove the dependencies as well:
sudo rm /usr/local/bin/{minikube,kubectl,docker-machine-driver-kvm2}