After being seeded with a variable namespace
and app name
(set as environment variables), this script will navigate through the Kubernetes api, and locate any underlying Persistent Volumes
and create a snapshot of each of these volumes.
Presently, only AWS is supported.
- The script will authenticate with AWS and K8 by looking for
~/.aws/credentials
and~/.kube/config
respectively.
- The script will authenticate with Kubernetes by using the local service account token attached to the pod that is deployed. See Accessing API from a Pod
- The script will authenticate with AWS via a secret which will mount a
config
andcredentials
file to/root/.aws
For this, a secret will have to already of been created. One method of creating this secret would be via Kubectl:
kubectl create secret --namespace=dev generic aws-key-secret --from-file=config=$HOME/.aws/config --from-file=credentials=$HOME/.aws/credentials
- Ensure
$HOME/.aws/
&$HOME/.kube/
store the appropriate credentials to your environment.
- From command line, run:
export $K8_NAMESPACE=<<your namespace>>
export $K8_APP_NAME=<<the application name>>
- From the root of this project:
- Install dependencies:
pip install -r ./requirements.txt
- Launch the script:
python -m kubernetes-pvc-snapshot
- Install dependencies:
- Use the following command to run the docker image from your local environment:
docker run -e K8_NAMESPACE="your-namespace" -e K8_APP_NAME="your-app-name" -v $HOME/.kube:/root/.kube/ -v $HOME/.aws:/root/.aws boysherman/kubernetes-snapshots
- Ensure aws 'secret' has been created on the cluster (see above How it works: running within Kubernetes cluster)
- in ./templates/helm/kubernetes-pvc-snapshot/values.yaml, update the following values:
- env.name_space
- env.app_name
- secret_name
- Package the helm chart. From within ./templates/helm, run:
helm package kubernetes-pvc-snapshot
- Deploy the helm chart.
helm install kubernetes-pvc-snapshot
To create a standard Kubernetes 'job':
- Provide a value to the keys
K8_NAMESPACE
&K8_APP_NAME
in ./templates/k8/kubernetes-volume-snapshot.yml - Create a new job via CLI:
kubectl --namespace dev create -f ./templates/k8/job--cassandra-backup.yml