-
Notifications
You must be signed in to change notification settings - Fork 108
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
csi: document how to use existing volumes #87
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
147 changes: 147 additions & 0 deletions
147
examples/kubernetes/pod-single-existing-volume/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
# Use an existing volume | ||
|
||
Below you will find the instruction on how to use an existing DigitalOcean Block | ||
Storage with your Kubernetes cluster. | ||
|
||
## Known issues | ||
|
||
* Deleting a `PVC` will delete the volume if the reclaim policy is set | ||
to `Delete`, however the bound `PV` will be not deleted. This seems to be a | ||
bug in K8S. | ||
* Using an existing, attached volume might cause confusion if the `POD` is | ||
scheduled to a different node. It's advised to use only existing **detached** | ||
volumes. If you have an attached volume, please make sure to detach it, so | ||
Kubernetes attaches it to the correct droplet. The CSI plugin will return an | ||
error if the volume is attached to a wrong droplet. | ||
|
||
## Example | ||
|
||
To use an existing volume, we have to create manually a `PersistentVolume` (PV) | ||
resource. Here is an example `PersistenVolume` resource for an existing volume: | ||
|
||
``` | ||
kind: PersistentVolume | ||
apiVersion: v1 | ||
metadata: | ||
name: volume-nyc1-01 | ||
annotations: | ||
# fake it by indicating this is provisioned dynamically, so the system | ||
# works properly | ||
pv.kubernetes.io/provisioned-by: com.digitalocean.csi.dobs | ||
spec: | ||
storageClassName: do-block-storage | ||
# by default, the volume will be not deleted if you delete the PVC, change to | ||
# "Delete" if you wish the volume to be deleted automatically with the PVC | ||
persistentVolumeReclaimPolicy: Delete | ||
capacity: | ||
storage: 5Gi | ||
accessModes: | ||
- ReadWriteOnce | ||
csi: | ||
driver: com.digitalocean.csi.dobs | ||
fsType: ext4 | ||
volumeHandle: 1952d58a-c714-11e8-bc0c-0a58ac14421e | ||
volumeAttributes: | ||
com.digitalocean.csi/format: "true" | ||
``` | ||
|
||
Couple of things to note, | ||
|
||
* `volumeHandle` is the volume ID you want to reuse. Make sure it matches exactly the volume you're targeting. You can list the ID's of your volumes via doctl: `doctl compute volume list` | ||
* `volumeAttributes` has a special, csi-digitalocean specific annotation called `com.digitalocean.csi/format`. If you add this key, the CSI plugin make sure to **not format** the volume. If you don't add this, it'll be formatted. | ||
* `storage` make sure it's set to the same storage size as your existing DigitalOcean Block Storage volume. | ||
|
||
Create a file with this content, naming it `pv.yaml` and deploy it: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
``` | ||
kubectl create -f pv.yaml | ||
``` | ||
|
||
View information about the `PersistentVolume`: | ||
|
||
``` | ||
$ kubectl get pv volume-nyc1-01 | ||
|
||
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE | ||
volume-nyc1-01 5Gi RWO Delete Available do-block-storage 15s | ||
``` | ||
|
||
The status is `Available`. This means it has not yet been bound to a | ||
PersistentVolumeClaim. Now we can proceed to create our PVC: | ||
|
||
|
||
``` | ||
apiVersion: v1 | ||
kind: PersistentVolumeClaim | ||
metadata: | ||
name: csi-pod-pvc | ||
spec: | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 5Gi | ||
storageClassName: do-block-storage | ||
``` | ||
|
||
This is the same (just like our other examples). When you create `PVC`, | ||
Kubernetes will try to match it to an existing `PV`. Because the | ||
storageClassName and the storage size matches our `PV` descriptions, kubernetes | ||
will bind this `PVC` to our manually create `PV`. CSI **will not** create a new | ||
volume because of the existing `PV`. | ||
|
||
Create the PersistentVolumeClaim: | ||
|
||
``` | ||
kubectl create -f pvc.yaml | ||
``` | ||
|
||
Now look at the PersistentVolumeClaim (PVC): | ||
|
||
``` | ||
kubectl get pvc task-pv-claim | ||
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE | ||
csi-pod-pvc Bound volume-nyc1-01 5Gi RWO do-block-storage 5s | ||
``` | ||
|
||
As you see, the output shows that the PVC is bound to our PersistentVolume, `volume-nyc1-01`. | ||
|
||
Finally, define your pod that refers to this PVC: | ||
|
||
``` | ||
kind: Pod | ||
apiVersion: v1 | ||
metadata: | ||
name: my-csi-app | ||
spec: | ||
containers: | ||
- name: my-frontend | ||
image: busybox | ||
volumeMounts: | ||
- mountPath: "/data" | ||
name: my-do-volume | ||
command: [ "sleep", "1000000" ] | ||
volumes: | ||
- name: my-do-volume | ||
persistentVolumeClaim: | ||
claimName: csi-pod-pvc | ||
``` | ||
|
||
|
||
Check if the pod is running successfully: | ||
|
||
|
||
``` | ||
$ kubectl describe pods/my-csi-app | ||
``` | ||
|
||
Write inside the app container: | ||
|
||
``` | ||
$ kubectl exec -ti my-csi-app /bin/sh | ||
/ # touch /data/hello-world | ||
/ # exit | ||
$ kubectl exec -ti my-csi-app /bin/sh | ||
/ # ls /data | ||
hello-world | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
kind: Pod | ||
apiVersion: v1 | ||
metadata: | ||
name: my-csi-app | ||
spec: | ||
containers: | ||
- name: my-frontend | ||
image: busybox | ||
volumeMounts: | ||
- mountPath: "/data" | ||
name: my-do-volume | ||
command: [ "sleep", "1000000" ] | ||
volumes: | ||
- name: my-do-volume | ||
persistentVolumeClaim: | ||
claimName: csi-pod-pvc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
kind: PersistentVolume | ||
apiVersion: v1 | ||
metadata: | ||
name: volume-nyc1-01 | ||
annotations: | ||
# fake it by indicating this is provisioned dynamically, so the system | ||
# works properly | ||
pv.kubernetes.io/provisioned-by: com.digitalocean.csi.dobs | ||
spec: | ||
storageClassName: do-block-storage | ||
# by default, the volume will be not deleted if you delete the PVC, change to | ||
# "Delete" if you wish the volume to be deleted automatically with the PVC | ||
persistentVolumeReclaimPolicy: Delete | ||
capacity: | ||
storage: 5Gi | ||
accessModes: | ||
- ReadWriteOnce | ||
csi: | ||
driver: com.digitalocean.csi.dobs | ||
fsType: ext4 | ||
volumeHandle: 1952d58a-c714-11e8-bc0c-0a58ac14421e | ||
volumeAttributes: | ||
com.digitalocean.csi/noformat: "true" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: v1 | ||
kind: PersistentVolumeClaim | ||
metadata: | ||
name: csi-pod-pvc | ||
spec: | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 5Gi | ||
storageClassName: do-block-storage |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
volume is attached to the wrong droplet(%q), detach the volume to fix it