How to copy/ backup an existing kubernetes resource and its related entities as well as a backup option
for example when I run kubectl get deploy my-deployment -n staging > backupdeploy.yaml
I get a file named backupdeploy.yaml with all the annotations and creation timestamps.
I need to be able to achieve a copy of the original my-deployment.yaml and the related resources in separate yamls. is there any shell script available to do this?
I also need the secrets, configmaps, svc, pvc that are tied to the " my-deployment "
Please help me out. Thanks.
In order to achieve that you need to use the --export
export flag:
If true, use 'export' for the resources. Exported resources are stripped of cluster-specific information.
So it would look like something like this: kubectl get deploy my-deployment -n staging --export
Please let me know if that helped.
Try running kubectl get pod <pod_name> -o yaml --export
but it's getting deprecated and no longer possible to use it; You can always try live editing it kubectl edit <pod>/<pod_name>
But the first command should help enough