Kubernetes identify if deployment or scale up

8/14/2018

I do some action on the start of the pod after deployment. But dont want to do it for scale up . Is there a way to identify when a pod is create if it is a new deployment or a scale up/recreate event

-- Amol
google-kubernetes-engine
kubernetes

2 Answers

8/23/2018

One possible solution would be to update a flag in your DB and have your script check against the value of that flag.

-- dany L
Source: StackOverflow

8/22/2018

So you want to run some db script on the first available pod after the deployment.

Will it work for you if you follow the following steps during the deployment creation:

$ kubectl apply -f app-deployment.yml

// This will give some time for the pod to start.
$ WAIT_BEFORE_DATABASE_SETUP="${WAIT_BEFORE_DATABASE_SETUP-120}"
$ sleep $WAIT_BEFORE_DATABASE_SETUP 

// Pick any one pod which is in Running State
$ APP_POD_NAME=$(kubectl get pods --field-selector=status.phase=Running -o=custom-columns=NAME:.metadata.name | grep <deployment-name> | head -1)

$ kubectl exec -it $APP_POD_NAME -- bash -c "/scripts/run_db_updates.sh"
-- Narendra
Source: StackOverflow