In K8S we have liveness and readiness. Both are running through full app lifecycle. But this is not enough for me. I would like to run some health check but only on start, or configure readiness to run only on start. Is it possible?
Take a look at handler lifecycle events, depending on the kind of health check probe you are doing the handler event will vary. I tried this on a simple "hello-world" pod. Set up a command in your postStart
event, and this will run only once, when the container is built and running. My example yaml file looks like this:
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-world
labels:
app: hello-world
spec:
replicas: 1
selector:
matchLabels:
app: hello-world
template:
metadata:
labels:
app: hello-world
spec:
containers:
- image: paulbouwer/hello-kubernetes:1.5
lifecycle:
postStart:
exec:
command: ["/bin/sh", "-c", "echo Hello from the postStart handler > /usr/share/message"]
name: hello-world
ports:
- containerPort: 8080
name: http