I would like to create a new namespace which is identical to the old one.
My approach would look something like this (full command below):
kubectl get <resources> -o json --namespace OLD-NAMESPACE | jq '.items[].metadata.namespace = "NEW-NAMESPACE"' | kubectl create -f -
This basically gets all resource definitions in a json format, replaces the old namespace with the new one, and applies everything.
Unfortunately, this does not work, since the old definitions contain namespace specific things. To avoid this, there used to be an --export
flag, which has been deprecated see here.
Any Idea how I could do this?
Full command:
kubectl get bindings,configmaps,endpoints,limitranges,persistentvolumeclaims,persistentvolumes,pods,podtemplates,replicationcontrollers,resourcequotas,secrets,mutatingwebhookconfigurations,validatingwebhookconfigurations,controllerrevisions,daemonsets,deployments,replicasets,statefulsets,tokenreviews,localsubjectaccessreviews,selfsubjectaccessreviews,selfsubjectrulesreviews,subjectaccessreviews,horizontalpodautoscalers,cronjobs,jobs,certificatesigningrequests,leases,endpointslices,events,ingressclasses,networkpolicies,runtimeclasses,poddisruptionbudgets,rolebindings,roles,debugattachments,csidrivers,volumeattachments -o json --namespace OLD-NAMESPACE | jq '.items[].metadata.namespace = "NEW-NAMESPACE"' | kubectl create -f -