I have a k8s cronjob run my docker image transaction-service
.
It starts and gets its job done successfully. When it's over, I expect the pod to terminate but... istio-proxy
still lingers there:
And that results in:
Nothing too crazy, but I'd like to fix it.
I know I should call curl -X POST http://localhost:15000/quitquitquit
But I don't know where and how. I need to call that quitquitquit URL only when transaction-service is in a completed state. I read about preStop
lifecycle hook, but I think I need more of a postStop
one. Any suggestions?
CodePudding user response:
You can use TTL mechanism for finished Jobs mentioned in kubernetes doc which help removing the whole pod.
CodePudding user response:
You have a few options here:
- On your job/cronjob spec, add the following lines and your job immediately after:
command: ["/bin/bash", "-c"]
args:
- |
trap "curl --max-time 2 -s -f -XPOST http://127.0.0.1:15020/quitquitquit" EXIT
while ! curl -s -f http://127.0.0.1:15020/healthz/ready; do sleep 1; done
echo "Ready!"
< your job >
- Disable Istio injection at the Pod level in your Job/Cronjob definition:
apiVersion: batch/v1beta1
kind: CronJob
metadata:
...
spec:
...
jobTemplate:
spec:
template:
metadata:
annotations:
# disable istio on the pod due to this issue:
# https://github.com/istio/istio/issues/11659
sidecar.istio.io/inject: "false"
Note: The annotation should be on the Pod's template, not on the Job's template.