How do I added a label to a Kubernetes pod when it has finished running it's startup script

4/14/2016

I have a pod that runs a script on startup. Once that script has finished executing I want to add a label to the pod so that it becomes available as part of a service. What is the best way to do this?

-- combinatorial
google-cloud-platform
kubernetes

1 Answer

4/14/2016

Instead of a label, you can use a readiness probe. If a readiness probe is set on a pod, then that probe will be continuously executed to detect whether that pod is considered "ready" and therefore should become available as part of a service. If the probe returns false or error, the pod will not be put into service. Probes can hit an HTTP endpoint or run a script inside the container.

In your case, your script could drop a file somewhere to indicate that the pod is ready. A separate script in your container (specified in the readiness probe) could return true only if that file is present.

More information on readiness checks can be found here.

(If you are still interested in adding a label to the pod, you can learn about service accounts which allow pods to communicate with the apiserver.)

-- ghodss
Source: StackOverflow