Delete AKS deployment's running pod on regular basis (Job)

2/13/2020

I have been struggling for some time to figure out how to accomplish the following: I want to delete running pod on Azure Kubernetes Service cluster on scheduled basis, so that it respawns from deployment. This is required that application re-reads configuration files stored on shared storage and shared with other application.

I have found out that Kubernetes Jobs might be handy to accomplish this, but there is some but. I cant figure how can I select corresponding pod related to my deployment as it adds random string to the deployment name, i.e

deployment-name-546fcbf44f-wckh4

Using selectors to get my pod doesnt succeed as there is not such operator like LIKE

kubectl get pods --field-selector metadata.name=deployment-name

No resources found

-- vrvrvrvrvr
azure-aks
kubernetes

1 Answer

2/13/2020

Looking at the official docs one way of doing this would be like so:

pods=$(kubectl get pods --selector=job-name=pi --output=jsonpath='{.items[*].metadata.name}')
echo $pods

you'd need to modify job-name to match your job name

https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/#running-an-example-job

-- 4c74356b41
Source: StackOverflow