v## What is this?
A simple Golang web app that demonstrates the HTTP GET /healthz
endpoint
pattern for Kubernetes readinessProbe
and livenessProbe
checks.
-
Clone this repo
$ git clone git@github.com:portertech/demo-app.git demo-app
-
Compile a statically linked binary of the demo-app app
$ cd demo-app $ CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' .
NOTE: Installing golang is left as an exercise for the reader.
-
Build a Docker image
$ docker build -t demo-app:latest .
NOTE: Installing docker and general help around building Docker containers is left as an exercise for the reader.
-
Run the container
$ docker run -p 8080:8080 -t demo-app:latest
-
Query the web app using curl to observe it running:
$ curl -XGET -I http://127.0.0.1:8080/healthz HTTP/1.1 200 OK Date: Wed, 18 Oct 2017 15:57:03 GMT Content-Length: 7 Content-Type: text/plain; charset=utf-8
NOTE: determining the IP address of your running container is left as an exercise for the reader; hint: run
docker ps
for clues. -
Toggle the status of the running app by posting to the
/healthz
endpoint:$ curl -XPOST -I http://127.0.0.1:8080/healthz HTTP/1.1 200 OK Date: Wed, 18 Oct 2017 15:58:21 GMT Content-Length: 0 Content-Type: text/plain; charset=utf-8
-
Query the web app again using curl to observe the "unhealthy" status:
$ curl -XGET -I http://127.0.0.1:8080/healthz HTTP/1.1 500 Internal Server Error Content-Type: text/plain; charset=utf-8 X-Content-Type-Options: nosniff Date: Wed, 18 Oct 2017 15:58:24 GMT Content-Length: 10