ksave.py
is a command-line interface (CLI) tool for backing up Kubernetes objects in YAML format. It supports various Kubernetes object types, such as Pods, Deployments, DaemonSets, Secrets, and more ...
ksave.py <object_type> <object_name> [options] > <output_file>
-pods
: Back up your Kubernetes Pod objects
-deployments
: Back up your Kubernetes Deployments objects
-daemonsets
: Back up your Kubernetes Daemonsets objects
-statefulsets
: Back up your Kubernetes Statefulsets objects
-cronjobs
: Back up your Kubernetes CronJob objects
-jobs
: Back up your Kubernetes Job objects
-secrets
: Back up your Kubernetes Secrets objects
-configmaps
: Back up your Kubernetes ConfigMap objects
-ingress
: Back up your Kubernetes Ingress objects
-services
: Back up your Kubernetes Services objects
-storageclass
: Back up your Kubernetes StorageClass objects
-persistentvolumes
: Back up your Kubernetes PersistentVolume objects
-peristentvolumeclaims
: Back up your Kubernetes PersistentVolumeClaim objects
-serviceaccount
: Back up your Kubernetes ServiceAccount objects
-roles
: Back up your Kubernetes Role objects
-rolebindings
: Back up your Kubernetes RoleBinding objects
-clusterroles
: Back up your Kubernetes ClusterRole objects
-clusterrolebindings
: Back up your Kubernetes ClusterRoleBinding objects
--namespace <namespace>
: Specify the namespace of the Kubernetes object.--all
: Backup objects from all namespaces.
To backup a specific Pod object:
ksave.py pods my_pod > my_pod.backup.yaml
To backup a Deployment object in a specific namespace:
ksave.py deployments my_deployment --namespace my_namespace > my_deployment.my_namespace.backup.yaml
To backup all DaemonSet objects:
ksave.py daemonsets --all > all_daemonsets.backup.yaml
To backup a Secret object:
ksave.py secrets my_secret > my_secret.backup.yaml
To display this help message and see all available options, use the --help
flag:
ksave.py --help
Usage: ksave [-h] {pods,deployments,daemonsets,statefulsets,cronjobs,jobs,secrets,configmaps,ingress,services,storageclass,persistentvolumes,peristentvolumeclaims,serviceaccount,roles,rolebindings,clusterroles,clusterrolebindings} ...
positional arguments:
{pods,deployments,daemonsets,statefulsets,cronjobs,jobs,secrets,configmaps,ingress,services,storageclass,persistentvolumes,peristentvolumeclaims,serviceaccount,roles,rolebindings,clusterroles,clusterrolebindings}
sub-command help
pods Back up your Kubernetes Pod objects
deployments Back up your Kubernetes Deployments objects
daemonsets Back up your Kubernetes Daemonsets objects
statefulsets Back up your Kubernetes Statefulsets objects
cronjobs Back up your Kubernetes CronJob objects
jobs Back up your Kubernetes Job objects
secrets Back up your Kubernetes Secrets objects
configmaps Back up your Kubernetes ConfigMap objects
ingress Back up your Kubernetes Ingress objects
services Back up your Kubernetes Services objects
storageclass Back up your Kubernetes StorageClass objects
persistentvolumes Back up your Kubernetes PersistentVolume objects
peristentvolumeclaims
Back up your Kubernetes PersistentVolumeClaim objects
serviceaccount Back up your Kubernetes ServiceAccount objects
roles Back up your Kubernetes Role objects
rolebindings Back up your Kubernetes RoleBinding objects
clusterroles Back up your Kubernetes ClusterRole objects
clusterrolebindings
Back up your Kubernetes ClusterRoleBinding objects
options:
-h, --help show this help message and exit
To activate individual virtual environment:
pip install virtualenv
To create and start in project root:
virtualenv venv
source venv/bin/activate
Install dependencies in virtual environment:
pip install -r requirements.txt
In this project, the Kubernetes Python Client proposed by kubernetes.io was used.
Kubernetes Python Client API Endpoint List -- Referance List
This CLI application is coded with arge-parse .