We've all seen it before: container is in bad shape, but you're not really sure wether to restart it,or how often to restart it, etc...
In kubernetes, A better way to handle containers, so that their statelessness is gauranteed as part of the application, is to use a livenessProbe, which automates in a flexible and declarative way, the logic of testing health of a container in case it needs to restart.
1) create a pod file as normal
2) add the livenessProbe to the container top level args:
- args
image
livenessProbe
3) select a type of probe (i.e. a command which determines death if non zero return, http get failure, or whatever, this is all listed in the docs).
for example
(liveness probe to test that 8080 is up and serving)
livenessProbe
httpGet
path: /hello
port: 8080
...
(liveness probe to test that a dir exists)
livenessProbe
exec
ls
....
4) start your pod.
Once the pod starts, you should see it restarting periodically whenever 8080 goes down or when the file you tried to "ls" is missing.
No comments:
Post a Comment