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

10/22/2020

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
-- cloudbud
kubectl
kubernetes

2 Answers

11/24/2021

Export is deprecated in latest version of Openshift. We can directly do it like below in openshift. Replace oc with kubectl if you are in kubernates.

oc get virtualservices --all-namespaces -o yaml > project.yaml  --> for all namespaces
oc get virtualservices -n <your-namespace>-all-namespaces -o yaml > project.yaml
-- Nilesh Kumar
Source: StackOverflow

10/22/2020

--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,

-- Kiruba
Source: StackOverflow