|
| 1 | +# RBD Volume to PV Mapping |
| 2 | + |
| 3 | +Authors: krmayankk@ |
| 4 | + |
| 5 | +### Problem |
| 6 | + |
| 7 | +The RBD Dynamic Provisioner currently generates rbd volume names which are random. |
| 8 | +The current implementation generates a UUID and the rbd image name becomes |
| 9 | +image := fmt.Sprintf("kubernetes-dynamic-pvc-%s", uuid.NewUUID()). This RBD image |
| 10 | +name is stored in the PV. The PV also has a reference to the PVC to which it binds. |
| 11 | +The problem with this approach is that if there is a catastrophic etcd data loss |
| 12 | +and all PV's are gone, there is no way to recover the mapping from RBD to PVC. The |
| 13 | +RBD volumes for the customer still exist, but we have no way to tell which rbd |
| 14 | +volumes belong to which customer. |
| 15 | + |
| 16 | +## Goal |
| 17 | +We want to store some information about the PVC in RBD image name/metadata, so that |
| 18 | +in catastrophic situations, we can derive the PVC name from rbd image name/metadata |
| 19 | +and allow customer the following options: |
| 20 | +- Backup RBD volume data for specific customers and hand them their copy before deleting |
| 21 | + the RBD volume. Without knowing from rbd image name/metadata, which customers they |
| 22 | + belong to we cannot hand those customers their data. |
| 23 | +- Create PV with the given RBD name and pre-bind it to the desired PVC so that customer |
| 24 | + can get its data back. |
| 25 | + |
| 26 | +## Non Goals |
| 27 | +This proposal doesnt attempt to undermine the importance of etcd backups to restore |
| 28 | +data in catastrophic situations. This is one additional line of defense in case our |
| 29 | +backups are not working. |
| 30 | + |
| 31 | +## Motivation |
| 32 | + |
| 33 | +We recently had an etcd data loss which resulted in loss of this rbd to pv mapping |
| 34 | +and there was no way to restore customer data. This proposal aims to store pvc name |
| 35 | +as metadata in the RBD image so that in catostrophic scenarios, the mapping can be |
| 36 | +restored by just looking at the RBD's. |
| 37 | + |
| 38 | +## Current Implementation |
| 39 | + |
| 40 | +```go |
| 41 | +func (r *rbdVolumeProvisioner) Provision() (*v1.PersistentVolume, error) { |
| 42 | +... |
| 43 | + |
| 44 | + // create random image name |
| 45 | + image := fmt.Sprintf("kubernetes-dynamic-pvc-%s", uuid.NewUUID()) |
| 46 | + r.rbdMounter.Image = image |
| 47 | +``` |
| 48 | +## Finalized Proposal |
| 49 | +Use `rbd image-meta set` command to store additional metadata in the RBD image about the PVC which owns |
| 50 | +the RBD image. |
| 51 | +
|
| 52 | +`rbd image-meta set --pool hdd kubernetes-dynamic-pvc-fabd715f-0d24-11e8-91fa-1418774b3e9d pvcname <pvcname>` |
| 53 | +`rbd image-meta set --pool hdd kubernetes-dynamic-pvc-fabd715f-0d24-11e8-91fa-1418774b3e9d pvcnamespace <pvcnamespace>` |
| 54 | +
|
| 55 | +### Pros |
| 56 | +- Simple to implement |
| 57 | +- Does not cause regression in RBD image names, which remains same as earlier. |
| 58 | +- The metada information is not immediately visible to RBD admins |
| 59 | +
|
| 60 | +### Cons |
| 61 | +- NA |
| 62 | +
|
| 63 | +Since this Proposal does not change the RBD image name and is able to store additional metadata about |
| 64 | +the PVC to which it belongs, this is preferred over other two proposals. Also it does a better job |
| 65 | +of hiding the PVC name in the metadata rather than making it more obvious in the RBD image name. The |
| 66 | +metadata can only be seen by admins with appropriate permissions to run the rbd image-meta command. In |
| 67 | +addition, this Proposal , doesnt impose any limitations on the length of metadata that can be stored |
| 68 | +and hence can accomodate any pvc names and namespaces which are stored as arbitrary key value pairs. |
| 69 | +It also leaves room for storing any other metadata about the PVC. |
| 70 | +
|
| 71 | +
|
| 72 | +## Proposal 1 |
| 73 | +
|
| 74 | +Make the RBD Image name as base64 encoded PVC name(namespace+name) |
| 75 | +
|
| 76 | +```go |
| 77 | +import b64 "encoding/base64" |
| 78 | +... |
| 79 | + |
| 80 | + |
| 81 | +func (r *rbdVolumeProvisioner) Provision() (*v1.PersistentVolume, error) { |
| 82 | +... |
| 83 | + |
| 84 | + // Create a base64 encoding of the PVC Namespace and Name |
| 85 | + rbdImageName := b64.StdEncoding.EncodeToString([]byte(r.options.PVC.Name+"/"+r.options.PVC.Namespace)) |
| 86 | + |
| 87 | + // Append the base64 encoding to the string `kubernetes-dynamic-pvc-` |
| 88 | + rbdImageName = fmt.Sprintf("kubernetes-dynamic-pvc-%s", rbdImageName) |
| 89 | + r.rbdMounter.Image = rbdImageName |
| 90 | + |
| 91 | +``` |
| 92 | +
|
| 93 | +### Pros |
| 94 | +- Simple scheme which encodes the fully qualified PVC name in the RBD image name |
| 95 | +
|
| 96 | +### Cons |
| 97 | +- Causes regression since RBD image names will change from one version of K8s to another. |
| 98 | +- Some older versions of librbd/krbd start having issues with names longer than 95 characters. |
| 99 | +
|
| 100 | +
|
| 101 | +## Proposal 2 |
| 102 | +
|
| 103 | +Make the RBD Image name as the stringified PVC namespace plus PVC name. |
| 104 | +
|
| 105 | +### Pros |
| 106 | +- Simple to implement. |
| 107 | +
|
| 108 | +### Cons |
| 109 | +- Causes regression since RBD image names will change from one version of K8s to another. |
| 110 | +- This exposes the customer name directly to Ceph Admins. Earlier it was hidden as base64 encoding |
| 111 | +
|
| 112 | +
|
| 113 | +## Misc |
| 114 | +- Document how Pre-Binding of PV to PVC works in dynamic provisioning |
| 115 | +- Document/Test if there are other issues with restoring PVC/PV after a |
| 116 | + etcd backup is restored |
0 commit comments