Skip to content

Instantly share code, notes, and snippets.

@magickatt
Created April 28, 2023 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magickatt/b54d00e41585951055ee4c7d91bee700 to your computer and use it in GitHub Desktop.
Save magickatt/b54d00e41585951055ee4c7d91bee700 to your computer and use it in GitHub Desktop.
Adopt Deployment Pod resources into a Helm install
# Can use https://gist.github.com/magickatt/e7885f748c2ecd5bb88dd64828b30fbf
# to adopt the Deployment resources themselves
NAME=test
NAMESPACE=default
kubectl get -n $NAMESPACE deployment -o name \
| xargs -I % kubectl patch -n $NAMESPACE % -p \
'{"spec": {"template":{"metadata":{"annotations":{"meta.helm.sh/release-name": "$NAME"}}}}}'
kubectl get -n $NAMESPACE deployment -o name \
| xargs -I % kubectl patch -n $NAMESPACE % -p \
'{"spec": {"template":{"metadata":{"annotations":{"meta.helm.sh/release-namespace": "$NAMESPACE"}}}}}'
kubectl get -n $NAMESPACE deployment -o name \
| xargs -I % kubectl patch -n $NAMESPACE % -p \
'{"spec": {"template":{"metadata":{"labels":{"app.kubernetes.io/managed-by": "Helm"}}}} }'
# Roll all the Deployments so the Pod resources are refreshed
for DEPLOY in `kubectl get deployments -n $NAMESPACE | tail -n +2 | cut -d ' ' -f 1`; do
kubectl rollout restart deployments/$DEPLOY -n $NAMESPACE
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment