Skip to content

Instantly share code, notes, and snippets.

@imixtron
Last active September 17, 2019 06:20
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 imixtron/7e097d99ca67f8e2431375db90cea7ea to your computer and use it in GitHub Desktop.
Save imixtron/7e097d99ca67f8e2431375db90cea7ea to your computer and use it in GitHub Desktop.
Copy secret between k8s namespaces
#!/bin/bash
kubectl get <resource-type> <resource-name> -n <source-namespace-name> -o yaml |\
sed 's/namespace: <source-namespace-name>/namespace: <target-namespace-name>/' |\
kubectl create -f -
> Example:
kubectl get secret auth-token -n web-dev -o yaml |\
sed 's/namespace: web-dev/namespace: web-qa/' |\
kubectl create -f -
=== DEPRECATED ===
since `--export` flag has been deprecated, we will be using `sed` to achieve our goal
ref:
- https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG-1.14.md#deprecations
- https://medium.com/@jonathan.johnson/export-has-been-deprecated-in-1-14-51cfef5a0cb7
kubectl get secret gitlab-registry --namespace=revsys-com --export -o yaml |\
kubectl apply --namespace=devspectrum-dev -f -
# thanks to
# https://www.revsys.com/tidbits/copying-kubernetes-secrets-between-namespaces/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment