|
1 | 1 | # k8s-keepalive
|
2 |
| -Container that keeps a k8s pod running |
| 2 | +## Introduction |
| 3 | +Over time I've found myself needing a way to keep a k8s pod alive either for debugging purposes or for interactive use. |
| 4 | + |
| 5 | +The typical recommendation on the internet is to use `tail -f /dev/null` or `/usr/bin/sleep infinity`. |
| 6 | + |
| 7 | +I've found a few issues with these two approaches: |
| 8 | +1. Both of those commands assume you have `tail` or `sleep` available in your image. |
| 9 | +2. If you don't have tail or sleep you *probably* need a package manager to install them. |
| 10 | +3. Unless you're careful, a package manager means more than just a single binary ending up in the image layer. |
| 11 | +4. Depending on configuration, `tail` and `sleep` dont respect `SIGINT` making killing the container annoying. |
| 12 | +5. There is no way robust way to configure Liveliness, Startup, or Readiness probes with `tail` and `sleep`. |
| 13 | + |
| 14 | +This binary attempts to solve all of the aforementioned challenges. The binary is written in golang and is statically linked, making it compatible with a wide range of environments. |
| 15 | + |
| 16 | +## Additional features |
| 17 | + |
| 18 | +For health checking you can point to `:5000/` or `:5000/healthz` to recieve a 200 OK. You can also type any valid HTTP status code after the `/` to recieve that status code back. |
| 19 | + |
| 20 | +Example: `:5000/404` will send back a 404 in the response header and body. |
| 21 | + |
| 22 | +## Usage |
| 23 | +### Installation options |
| 24 | +#### Run |
| 25 | +To run it standalone: |
| 26 | + |
| 27 | +`docker run -p 8080:5000 mikecallahan/k8s-keepalive:1.0.0` |
| 28 | + |
| 29 | +#### Copy the binary |
| 30 | +Download the latest release, `COPY` it into your Dockerfile, and use it in your `ENTRYPOINT [""]` or `CMD [""]` when you need it. |
| 31 | + |
| 32 | +#### Public image |
| 33 | +Use the public image in a multi-stage build: |
| 34 | +``` |
| 35 | +FROM mikecallahan/k8s-keepalive:1.0.0 as build |
| 36 | +
|
| 37 | +--your docker file starts here --- |
| 38 | +FROM ... |
| 39 | +COPY --from=build /usr/bin/k8s-keepalive /usr/bin/k8s-keepalive |
| 40 | +``` |
| 41 | + |
| 42 | +#### Update a yaml file |
| 43 | +If you have an existing image already deployed in k8s, and your image has `wget` or `curl`, update your deployment.yaml: |
| 44 | + |
| 45 | +``` |
| 46 | +spec: |
| 47 | + containers: |
| 48 | + - name: my-existing-container |
| 49 | + image: ubuntu:latest |
| 50 | + command: ["/bin/sh"] |
| 51 | + args: ["-c", "curl -OL https://github.com/mike-callahan/k8s-keepalive/releases/download/v1.0.0/k8s-keepalive && ./k8s-keepalive"] |
| 52 | +``` |
| 53 | +## Roadmap |
| 54 | +- [x] Keep container running |
| 55 | +- [x] Support health checks |
| 56 | +- [x] Statically link binary (net package) |
| 57 | +- [x] Release Dockerfile and image |
| 58 | +- [x] Support native `SIGINT` and `SIGTERM` |
| 59 | +- [ ] Cross-compile for Windows |
0 commit comments