I needed a simple, fast to compile, install and modify Container/POD for Kubernetes with some logging, health checks and a way to get it to die by curl call for simple tests of Kubernetes resilience logic.
I have tested it under ArchLinux using minikube.
Call the buildGo.sh
to compile the Go binary. The script set CGO_ENABLED=0
to avoid differences between the build system and the Docker system (like having
different libc implementations).
Call buildDocker.sh
to build the Docker file and move into the registry. For minikube
call
eval $(minikube docker-env)
to place the Docker image directly into the minikube registry.
- (Optionally) Patch the
deployment.yaml
for your needs - (Optionally) Create a namespace:
kubectl create namespace minitestpod
- Import the yaml:
kubectl create -f deployment.yaml
/
- a nice hello world response/liveness
- a HTTP 200 OK/readiness
- a HTTP 200 OK/die
- Immediate OS.exit(), Kubernetes should detect this and should restart the POD
NAME
- Change the name in the log messagesPORT
- Change the port of the internl HTTP server
curl --header "Host:kubetestpod.example.com" 192.168.99.100/die
(You need the header to get the ingress working in cases where DNS resolving is not activated)
Get the pods
kubectl get pods --namespace kubetestpod
Get the ingress (access form the outside)
kubectl get ingress --namespace kubetestpod
Get the events
kubectl get events --namespace kubetestpod
Get the logs (pod name and namespace may be different)
kubectl logs -f kubetestpod-6877f6945b-tgx77 --namespace kubetestpod
Go is not my first language.
Patches welcome!