Skip to content

Commit

Permalink
Merge pull request #1 from calebhailey/master
Browse files Browse the repository at this point in the history
A few changes that made this easier for me :)
  • Loading branch information
portertech authored Nov 7, 2017
2 parents 37837d7 + 425c93c commit 881ca88
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 3 deletions.
10 changes: 8 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
FROM golang:1.8.4-onbuild
EXPOSE 80
FROM alpine:latest

RUN apk --no-cache add curl
COPY dummy /usr/bin/dummy

EXPOSE 8080

CMD ["/usr/bin/dummy"]
73 changes: 73 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
## What is this?

A simple Golang web app that demonstrates the HTTP `GET /healthz` endpoint
pattern for Kubernetes `readinessProbe` and `livenessProbe` checks.

## How do I use it?

1. Clone this repo

```
$ git clone git@github.com:portertech/dummy.git dummy
```

2. Compile a statically linked binary of the dummy app

```
$ cd dummy
$ CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' .
```

_NOTE: Installing golang is left as an exercise for the reader._

3. Build a Docker image

```
$ docker build -t dummy:latest .
```

_NOTE: Installing docker and general help around building Docker containers
is left as an exercise for the reader._

4. Run the container

```
$ docker run -p 8080:8080 -t dummy:latest
```

5. 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._

6. 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
```

7. 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
```
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func main() {

srv := &http.Server{
Handler: r,
Addr: ":80",
Addr: ":8080",
WriteTimeout: 5 * time.Second,
ReadTimeout: 5 * time.Second,
}
Expand Down

0 comments on commit 881ca88

Please sign in to comment.