Last active
July 6, 2024 13:12
-
-
Save adamency/b92bf632dd04f02b967edd07374c5c90 to your computer and use it in GitHub Desktop.
Move Kubernetes Resource from one namespace to another
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kubectl get -n <old_namespace> <kind> <resource> -o json |\ | |
jq '.metadata.namespace = "<new_namespace>"' |\ | |
kubectl create -f - &&\ | |
kubectl delete -n <old_namespace> <kind> <resource> |
Adding here what I read on Reddit regarding this script because I think it might be useful (and for myself to remind me because I've starred this gist):
I see what you're saying because of the
&&
. Still I wouldn't simply trust that a successful exit of kubectl would be enough for me to go and delete the resource. But I'm very cautious. Personally, I'd query the API again and check the status of the newly-created one first... You could use jq again, if you want to keep it in a shell script
@PrimeDominus This is what I explained in the comment above. But always a good idea to add more information :). Thanks for starring the gist !
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Beware that this will copy the
status
section of your resource to the new one, and depending on thekind
, this may have non-intended repercussions, but this should be fine forConfigMaps
andSecrets
.