Tutorial: Migrate Stateful Kubernetes Workloads with Portworx and Velero

In the last part of this tutorial series, we have seen how to take snapshots of Portworx volumes and store them in S3-compatible object storage services like MinIO. We will extend that scenario to migrate stateful workloads across namespaces, clusters, and even cloud providers. By the end of this tutorial, you will be able to migrate WordPress from one namespace to another.
Since this is a continuation of the previous tutorial, it assumes that you followed the steps of installing MinIO and registering it with Portworx before proceeding further (Or start from the beginning: Part 1, Part 2, Part 3, Part 4).
Portworx has a mature, enterprise-grade backup and restore for Kubernetes backup. This guide is an alternate approach to using the backup and migration features of Portworx. This tutorial works with both Portworx Essentials and Portworx Enterprise.
Installing Velero
Velero (formerly Heptio Ark) is a tool to backup and restore Kubernetes cluster resources and persistent volumes. It installs as a CRD in Kubernetes to backup an entire namespace or specific resources that match a specific label.
Follow the instructions from the documentation to download and install Velero.
Valero’s backup can be stored in an Amazon S3 bucket. We will use MinIO instead of Amazon S3. Make sure you add the MinIO secret key and access key credentials to the file credentials-velero located in the current directory. Refer to the Velero documentation for more information on this configuration.
Replace the URLs with your MinIO endpoint.
1 2 3 4 5 6 7 |
velero install \ --provider aws \ --plugins velero/velero-plugin-for-aws:v1.0.0 \ --bucket wp-backup \ --secret-file ./credentials-velero \ --use-volume-snapshots=false \ --backup-location-config region=minio,s3ForcePathStyle="true",s3Url=http://10.0.0.5:9000,publicUrl=http://10.0.0.5:9000 |
This results in the creation of the namespace velero and a pod running within that.
1 |
kubectl get pods -n velero |
We have Velero ready to take the backup of a workload and store it in the MinIO bucket. This was done by adding the AWS plugin along with the pointer to the bucket URL.
Notice that Velero is not aware of Portworx at this point which means it cannot take volume snapshots of PVCs. In the next step, we will point Velero to Portworx to use its volume snapshot feature along with the backup.
Configuring Portworx Provider for Velero
Velero uses a plugin model for backups stored in object storage and volume snapshots of block storage. In this scenario, we are using the AWS plugin for object storage and the Portworx plugin for the volume snapshots.
1 |
velero plugin add portworx/velero-plugin:1.0.0 |
The above command registers the Portworx plugin with Velero. The next step is to point Velero to the default location for snapshots as configured by Portworx. In the previous tutorial, we registered the credentials for MinIO with Portworx to store the volume snapshots in one of the buckets. Velero will continue to use the same configuration each time the backup is initiated.
1 2 3 |
velero snapshot-location create portworx-cloud \ --provider portworx.io/portworx \ --config type=cloud |
We just instructed Velero to use the default remote snapshot configuration of Portworx for volume snapshots.
This integration enables Velero to backup Kubernetes resources such as deployments, services, ingress while delegating the volume snapshot job to Portworx. The same process is followed during the restore process.
Backing up WordPress Application with Velero
We are now ready to initiate the backup with Velero. Run the below command to kick off the job.
1 2 3 4 |
velero backup create wp-backup \ --include-namespaces=wordpress \ --snapshot-volumes \ --volume-snapshot-locations portworx-cloud |
Check the status by running the ‘velero backup get’ command.
Once it is done, check the MinIO browser. There would be two buckets — one to store volume snapshots created by Portworx and the other for storing Velero backup for the entire workload.
The two objects corresponding to the MySQL and WordPress PVCs are seen here.
The bucket, wp-backup, is used by Velero to dump the complete backup of Kubernetes objects from the WordPress namespace.
Performing a Restore with Velero
With the backup in place, let’s test the restore process with Velero.
We will first delete the wordpress namespace to remove all associated resources with the application including the PVCs.
1 |
kubectl delete ns wordpress |
Let’s attempt the restore now.
1 |
velero restore create --from-backup wp-backup |
Check the status with the below command:
1 |
velero get restore wp-backup-20200430120109 |
Velero has restored all the resources to the same namespace, WordPress.
1 |
kubectl get all -n wordpress |
The restore process involved Velero in recreating the Kubernetes objects and Portworx in creating the PVCs from cloud snapshots.
The same workflow can be used to migrate stateful workloads across clusters provided you have identical environments with Portworx and Velero installations.
This article concludes the series on running stateful workloads with Portworx.
Janakiram MSV’s Webinar series, “Machine Intelligence and Modern Infrastructure (MI2)” offers informative and insightful sessions covering cutting-edge technologies. Sign up for the upcoming MI2 webinar at http://mi2.live.
Portworx is a sponsor of The New Stack.
Feature image by Siggy Nowak from Pixabay.