Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unknown flag: --export while copying secret from one namespace to another kubectl

I am getting error while copying the kubernetes secret from one namespace to another:

kubectl get secret secret1 --namespace=test --export -o=yaml | kubectl apply --namespace=test1 -f -

Error: unknown flag: --export
See 'kubectl get --help' for usage.
error: no objects passed to apply
like image 857
cloudbud Avatar asked Oct 22 '20 12:10

cloudbud


People also ask

How do I copy a secret from one namespace to another namespace?

If you need to copy a secret from one namespace to another, you will get an error because the 'namespace' is still embedded in the yaml and cannot be overridden with the final apply. By using a sed replacement as a filter, you can do a quick transformation and get your desired result.


1 Answers

--export option has been deprecated in version 1.14 and removed in version 1.18. If you are using kubernetes version 1.18 or above, you can try using below command (using sed) to copy secret from one namespace to other.

kubectl get secret secret1 --namespace=test -o yaml | sed 's/namespace: test/namespace: test1/g' | kubectl create -f -  

Thanks,

like image 108
Kiruba Avatar answered Oct 19 '22 09:10

Kiruba