Skip to content

Instantly share code, notes, and snippets.

@jcderr
Created June 7, 2017 19:59
Show Gist options
  • Save jcderr/5e07be83358a070f407f453e66a70167 to your computer and use it in GitHub Desktop.
Save jcderr/5e07be83358a070f407f453e66a70167 to your computer and use it in GitHub Desktop.
K8S Deployment Dev-nuller
#!/bin/bash
# Usage: devnuller <deployment>
# When troubleshooting k8s deployments, it is sometimes helpful to set command: ["tail", "-f", "/dev/null"]
# so that you have a long-running null-command, allowing you to `kubectl exec ...` in and troubleshoot the
# environment. This will do that, and tell you how to roll back your command.
DEPLOYMENT="
P_REV=$(kubectl get deployment/${DEPLOYMENT} -o json | \
jq -r '.metadata.annotations["deployment.kubernetes.io/revision"]')
echo "---> Dev Nuller: Command will be set to `tail -f /dev/null`"
echo "---> Rollback command:"
echo "kubectl rollout undo deployment/${DEPLOYMENT} --to-revision=${P_REV}"
echo -n "Proceed? [N/y]"; read PROCEED
if [[ "${PROCEED}" == "y" ]]; then
kubectl patch deployment/${DEPLOYMENT} \
--type="json" \
-p="[{\"op\": \"replace\", \"path\": \"/spec/template/spec/containers/0/command\", \
\"value\":[\"tail\", \"-f\", \"/dev/null}\"}]"
else
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment