The status of a deployment indicates that you can look at a deployments observedGeneration vs generation and when observedGeneration >= genera
Just use a rollout status:
kubectl rollout status deployment/
This will run in foreground, it waits and displays the status, and exits when rollout is complete on success or failure. If you're writing a shell script, then check the return code right after the command, something like this.
kubectl rollout status deployment/
if [[ "$?" -ne 0 ]] then
echo "deployment failed!"
exit 1
fi
To even further automate your script:
deployment_name=$(kubectl get deployment -n | awk '!/NAME/{print $1}')
kubectl rollout status deployment/"${deployment_name}" -n
if [[ "$?" -ne 0 ]] then
echo "deployment failed!"
#exit 1
else
echo "deployment succeeded"
fi
If you're running in default namespace then you could leave out the -n