Over time I've found myself needing a way to keep a k8s pod alive either for debugging purposes or for interactive use.
The typical recommendation on the internet is to use tail -f /dev/null
or /usr/bin/sleep infinity
.
I've found a few issues with these two approaches:
- Both of those commands assume you have
tail
orsleep
available in your image. - If you don't have tail or sleep you probably need a package manager to install them.
- Unless you're careful, a package manager means more than just a single binary ending up in the image layer.
- Depending on configuration,
tail
andsleep
dont respectSIGINT
making killing the container annoying. - There is no way robust way to configure Liveliness, Startup, or Readiness probes with
tail
andsleep
.
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.
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.
Example: :5000/404
will send back a 404 in the response header and body.
To run it standalone:
docker run -p 8080:5000 mikecallahan/k8s-keepalive:1.0.0
Download the latest release, COPY
it into your Dockerfile, and use it in your ENTRYPOINT [""]
or CMD [""]
when you need it.
Use the public image in a multi-stage build:
FROM mikecallahan/k8s-keepalive:1.0.0 as build
--your docker file starts here ---
FROM ...
COPY --from=build /usr/bin/k8s-keepalive /usr/bin/k8s-keepalive
If you have an existing image already deployed in k8s, and your image has wget
or curl
, update your deployment.yaml:
spec:
containers:
- name: my-existing-container
image: ubuntu:latest
command: ["/bin/sh"]
args: ["-c", "curl -OL https://github.com/mike-callahan/k8s-keepalive/releases/download/v1.0.0/k8s-keepalive && ./k8s-keepalive"]
- Keep container running
- Support health checks
- Statically link binary (net package)
- Release Dockerfile and image
- Support native
SIGINT
andSIGTERM
- Cross-compile for Windows