<p>We have a release pipeline in AzureDevops to deploy the microservice to AKS and send the log of the microservice once its deployed.
We are using below command to deploy the deployment with the template kubectl and command as "-f /home/admin/builds/$(build.buildnumber)/Myservice_Deployment.yml --record"</p>

<p>Here we noticed that the task is not waiting for the existing pod to terminate and crate the new pod, but its continuing and just finishing the job.</p>

<p>Our expected scenario</p>

<p>1) Deploy the microservice using kubectl apply -f /home/admin/builds/$(build.buildnumber)/Myservice_Deployment.yml --record</p>

<p>2) wait for the existing pod to terminate and ensure that the new pod is in running status.</p>

<p>3) once the new pod is running status collect the log of the pod by kubectl log command and sent to the team</p>

<p>4) if the pod is not is not in running state, roll back to previous stable state.</p>

<p>I tried with different shell scripts to achieve this in azuredevops, but didnt succeeded</p>

<p>Ex: </p>

<pre><code>
ATTEMPTS=0
ROLLOUT_STATUS_CMD="kubectl --kubeconfig /home/admin/kubernetes/Dev-kubeconfig rollout status deployment/My-service"
until $ROLLOUT_STATUS_CMD || [ $ATTEMPTS -eq 60 ]; do
  $ROLLOUT_STATUS_CMD
  ATTEMPTS=$((attempts + 1))
  sleep 10
done
</code></pre>

<p>Also need to get the log of the microservice using the kubectl log command and the file should be in the format with Date and need to be shared over mail..</p>

vyshakh
<p>you have several questions mixed up in a single question, but you'd need to configure your deployment with liveness probe for your desired behaviour to happen</p>

<p>Reading: <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-a-liveness-command" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-a-liveness-command</a></p>
