-
Notifications
You must be signed in to change notification settings - Fork 14.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add volume backup and restore tutorial #49452
base: main
Are you sure you want to change the base?
Conversation
✅ Pull request preview available for checkingBuilt without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
This PR resolve the issue Document backing Up Container Using Kubernetes . Mostly focused on the #43307 (comment) to do a simple backup of a volume, such as saving a gzip copy of the backing storage, delete the PersistentVolume and its storage, and then restore. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few suggestions for now.
content/en/docs/tutorials/volume-backup/volume-backup-restore.md
Outdated
Show resolved
Hide resolved
content/en/docs/tutorials/volume-backup/volume-backup-restore.md
Outdated
Show resolved
Hide resolved
content/en/docs/tutorials/volume-backup/volume-backup-restore.md
Outdated
Show resolved
Hide resolved
content/en/docs/tutorials/volume-backup/volume-backup-restore.md
Outdated
Show resolved
Hide resolved
@network-charles updated with suggested change PTAL! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
Does the inline feedback make sense here?
content/en/docs/tutorials/volume-backup/volume-backup-restore.md
Outdated
Show resolved
Hide resolved
content/en/docs/tutorials/volume-backup/volume-backup-restore.md
Outdated
Show resolved
Hide resolved
content/en/docs/tutorials/volume-backup/volume-backup-restore.md
Outdated
Show resolved
Hide resolved
Alright. I think you should mark the suggestions as resolved too. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Thank You @network-charles for the suggestion i marked the resolved one as resolve . |
/retitle Add volume backup and restore tutorial |
1. Restoring applications with backed-up data | ||
1. Practical workflow for backup and restore | ||
|
||
## Configure Persistent Volume and Persistent Volume Claim |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow the style guide here if you can.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid that this needs a lot of work to become something that we could merge.
Overall, make sure that you understand how to manage Kubernetes storage and manually trigger snapshots; also that you know how to restore data from such a snapshot.
You should acquire or confirm this knowledge even if you explain a different approach, so that you can help readers understand a cloud native way to take a backup.
|
||
### Create Backup | ||
|
||
The process involves accessing the pod to interact with its file system, navigating to the mounted volume directory ```(/usr/local/apache2/htdocs)``` containing the data to be backed-up, and compressing the directory contents into a ```.tar.gz``` file stored in the pod's temporary directory ```(/tmp)```. After exiting the pod shell, the backup file is transferred to the local machine using ```kubectl cp```, ensuring the data is securely saved outside the pod environment for restoration or safekeeping. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The process involves accessing the pod to interact with its file system, navigating t
the mounted volume directory (/usr/local/apache2/htdocs
) containing the data to be
backed up, and archive the directory contents using tar and gzip. You temporarily store the
archive within a pod's ephemeral storage.
After exiting the pod shell, the backup file is transferred to the local machine using kubectl cp
,
ensuring the data is securely saved outside the pod environment for restoration or safekeeping.
Even better:
- at least mention [snapshots](https://kubernetes.io/docs/concepts/storage/volume-snapshots/)
- avoid `kubectl cp`
- make sure that `/tmp` is an `emptyDir` volume when you work with it.
|
||
This command opens an interactive shell inside the specified pod (pv-pod-backup). | ||
|
||
**Navigate to the Mounted Volume Directory:** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a subheading
``` | ||
This directory contains the data you wish to backup. | ||
|
||
**Create a Compressed Backup File (gzip):** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a subheading
``` | ||
exit | ||
``` | ||
**Copy the Backup to Local Machine:** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a subheading
### Delete the data from volume | ||
To understand the backup use, The process involves accessing the pod to navigate to the mounted volume directory ```/usr/local/apache2/htdocs```, deleting all files and subdirectories within it using ```rm -rf *```, and verifying the deletion by listing the directory contents ```ls -l```. Finally, the pod shell is exited after confirming the directory is empty. | ||
|
||
**Access the Pod Again:** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a subheading
```shell | ||
kubectl exec -it task-pv-pod -- /bin/bash | ||
``` | ||
**Extract the Backup:** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a subheading
cd /usr/local/apache2/htdocs | ||
tar -xzvf /tmp/volume-backup.tar.gz | ||
``` | ||
**Verify the Restoration:** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a subheading
To run the restored file run | ||
```shell | ||
# Be sure to run these 3 commands inside the root shell that comes from | ||
# running "kubectl exec" in the previous step | ||
apt update | ||
apt install curl | ||
curl http://localhost/ | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're not running the file that has been restored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The restored file in this context is index.html. To verify its contents, I am using the command:
curl http://localhost
This displays the output stored within the file, ensuring that the restoration process was successful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To run the restored file run
This is misleading or wrong.
[backup_heading] | ||
other = "Backup, Delete and Restore Volumes" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to change this file.
## {{% heading "prerequisites" %}} | ||
Before you begin this tutorial, you should be familiar with the following Kubernetes concepts: | ||
|
||
* [Pods](/docs/concepts/workloads/pods/) | ||
* [PersistentVolumes](/docs/concepts/storage/persistent-volumes/) | ||
* The [kubectl](/docs/reference/kubectl/kubectl/) command line tool | ||
|
||
## {{% heading "prerequisites" %}} | ||
|
||
* You need to have a Kubernetes cluster that has only one Node, and the | ||
{{< glossary_tooltip text="kubectl" term_id="kubectl" >}} | ||
command-line tool must be configured to communicate with your cluster. If you | ||
do not already have a single-node cluster, you can create one by using | ||
[Minikube](https://minikube.sigs.k8s.io/docs/). | ||
|
||
* Familiarize yourself with the material in | ||
[Persistent Volumes](/docs/concepts/storage/persistent-volumes/). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are there two prerequisites sections?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New suggestions
1. Practical workflow for backup and restore | ||
|
||
## Configure Persistent Volume and Persistent Volume Claim | ||
Use the existing yaml file from the [Configure a Pod to Use a PersistentVolume for Storage](/tasks/configure-pod-container/configure-persistent-volume-storage/) task to configure PersistentVolume (PV) and PersistentVolumeClaim (PVC). Then follow the steps from the beginning, to create a `hostpath` and `index.html` file as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean by "follow the steps from the beginning". I'm already thinking, "Do you mean, from the beginning of this page, or the beginning of the page in the URL?
Here's my suggestion for you.
Use the existing yaml file from the [Configure a Pod to Use a PersistentVolume for Storage](/tasks/configure-pod-container/configure-persistent-volume-storage/) task to configure PersistentVolume (PV) and PersistentVolumeClaim (PVC). Then follow the steps from the beginning, to create a `hostpath` and `index.html` file as well. | |
Follow the steps in the [Configure a Pod to Use a PersistentVolume for Storage](/tasks/configure-pod-container/configure-persistent-volume-storage/) | |
task to create an `index.html` file, a PersistentVolume (PV), and PersistentVolumeClaim (PVC). |
``` | ||
|
||
## Create a Pod | ||
The next step is to create a Pod that uses your PersistentVolumeClaim as a volume. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The next step is to create a Pod that uses your PersistentVolumeClaim as a volume. | |
The next step is to create a Pod running an httpd server that uses your PersistentVolumeClaim as a volume. |
kubectl exec -it pv-pod-backup -- /bin/bash | ||
``` | ||
|
||
In your shell, verify that httpd:2.4 is serving the `index.html` file from the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not say, "the httpd server", rather than specifying it with the image tag so it's comprehensible?
In your shell, verify that httpd:2.4 is serving the `index.html` file from the | |
In your shell, verify that the httpd server is serving the `index.html` file from the |
|
||
### Create Backup | ||
|
||
The process involves accessing the pod to interact with its file system, navigating to the mounted volume directory ```(/usr/local/apache2/htdocs)``` containing the data to be backed-up, and compressing the directory contents into a ```.tar.gz``` file stored in the pod's temporary directory ```(/tmp)```. After exiting the pod shell, the backup file is transferred to the local machine using ```kubectl cp```, ensuring the data is securely saved outside the pod environment for restoration or safekeeping. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Markdown supports a single backtick for one line of code. You can use triple backticks for a multi-line code.
The process involves accessing the pod to interact with its file system, navigating to the mounted volume directory ```(/usr/local/apache2/htdocs)``` containing the data to be backed-up, and compressing the directory contents into a ```.tar.gz``` file stored in the pod's temporary directory ```(/tmp)```. After exiting the pod shell, the backup file is transferred to the local machine using ```kubectl cp```, ensuring the data is securely saved outside the pod environment for restoration or safekeeping. | |
The process involves accessing the Pod to interact with its file system, navigating to the mounted volume directory | |
`(/usr/local/apache2/htdocs)` containing the data to be backed-up, and compressing the directory contents into a | |
`.tar.gz` file stored in the Pod's temporary directory `(/tmp)`. After exiting the Pod shell, the backup file is transferred to the local machine using `kubectl cp`, ensuring the data is securely saved outside the pod environment for restoration or safekeeping. |
```shell | ||
kubectl cp pv-pod-backup:/tmp/volume-backup.tar.gz ./volume-backup.tar.gz | ||
``` | ||
This saves the backup file ```volume-backup.tar.gz``` in your current local directory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This saves the backup file ```volume-backup.tar.gz``` in your current local directory. | |
This saves the backup file `volume-backup.tar.gz` in your current local directory. |
To understand the backup use, The process involves accessing the pod to navigate to the mounted volume directory ```/usr/local/apache2/htdocs```, deleting all files and subdirectories within it using ```rm -rf *```, and verifying the deletion by listing the directory contents ```ls -l```. Finally, the pod shell is exited after confirming the directory is empty. | ||
|
||
**Access the Pod Again:** | ||
To delete the data from the volume, access the pod that uses the volume: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the style-guide.
To delete the data from the volume, access the pod that uses the volume: | |
To delete the data from the volume, access the Pod that uses the volume: |
kubectl exec -it task-pv-pod -- /bin/bash | ||
``` | ||
**Navigate to the Mounted Volume Directory:** | ||
Inside the pod, go to the directory where the volume is mounted: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inside the pod, go to the directory where the volume is mounted: | |
Inside the Pod, go to the directory where the volume is mounted: |
This copies the backup file to the /tmp directory of the pv-pod-backup pod. | ||
|
||
**Access the Pod:** | ||
Open an interactive shell inside the pod: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Open an interactive shell inside the pod: | |
Open an interactive shell inside the Pod: |
exit | ||
``` | ||
### Test the Restored Data | ||
Now Check the status of the Pod ```pv-pod-backup``` Whether it is in ```Running``` state or not. If it is in ```Running``` state then restoring the volume worked perfectly fine. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now Check the status of the Pod ```pv-pod-backup``` Whether it is in ```Running``` state or not. If it is in ```Running``` state then restoring the volume worked perfectly fine. | |
Now Check the status of the `pv-pod-backup` Pod to see whether it is in a `Running` state or not. If it is in a `Running` state, then restoring the volume worked perfectly fine. |
```shell | ||
kubectl get pod pv-pod-backup -o wide | ||
``` | ||
Now You can again check the output by access the pods |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now You can again check the output by access the pods | |
Now You can again check the output by accessing the Pods shell |
Description
A tutorial about how to do a simple backup of a volume, such as saving a gzip copy of the backing storage, delete the volume and restore it.
Issue
Document Backing Up Volume #43307