Skip to content

Commit

Permalink
Merge pull request #238 from leakingtapan/readme
Browse files Browse the repository at this point in the history
Add example for block volume
  • Loading branch information
Cheng Pan committed Mar 12, 2019
2 parents 65941b6 + 46bc068 commit 0c6b853
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
39 changes: 39 additions & 0 deletions examples/kubernetes/block-volume/README.md
@@ -0,0 +1,39 @@
## Raw Block Volume
This example shows how to consume a dynamically-provisioned EBS volume as a raw block device.

### Edit [Persistence Volume Claim Spec](./specs/raw-claim.yaml)
Make sure the `volumeMode` is `Block`.

### Edit [Application Pod](./specs/pod.yaml)
Make sure the pod is consuming the PVC with the defined name and `volumeDevices` is used instead of `volumeMounts`.

### Deploy the Application
```sh
kubectl apply -f examples/kubernetes/block-volume/specs/storageclass.yaml
kubectl apply -f examples/kubernetes/block-volume/specs/raw-claim.yaml
kubectl apply -f examples/kubernetes/block-volume/specs/pod.yaml
```

### Access Block Device
After the objects are created, verify that pod is running:

```sh
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
app 1/1 Running 0 16m
```
Verify the device node is mounted inside the container:

```sh
$ kubectl exec -ti app -- ls -al /dev/xvda
brw-rw---- 1 root disk 202, 23296 Mar 12 04:23 /dev/xvda
```

Write to the device using:

```sh
dd if=/dev/zero of=/dev/xvda bs=1024k count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB, 100 MiB) copied, 0.0492386 s, 2.1 GB/s
```
17 changes: 17 additions & 0 deletions examples/kubernetes/block-volume/specs/pod.yaml
@@ -0,0 +1,17 @@
apiVersion: v1
kind: Pod
metadata:
name: app
spec:
containers:
- name: app
image: busybox
command: ["/bin/sh", "-c"]
args: ["tail -f /dev/null"]
volumeDevices:
- name: data
devicePath: /dev/xvda
volumes:
- name: data
persistentVolumeClaim:
claimName: block-claim
12 changes: 12 additions & 0 deletions examples/kubernetes/block-volume/specs/raw-claim.yaml
@@ -0,0 +1,12 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: block-claim
spec:
accessModes:
- ReadWriteOnce
volumeMode: Block
storageClassName: ebs-sc
resources:
requests:
storage: 10Gi
6 changes: 6 additions & 0 deletions examples/kubernetes/block-volume/specs/storageclass.yaml
@@ -0,0 +1,6 @@
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: ebs-sc
provisioner: ebs.csi.aws.com
volumeBindingMode: WaitForFirstConsumer
2 changes: 1 addition & 1 deletion examples/kubernetes/pod-single-volume/README.md
Expand Up @@ -26,4 +26,4 @@ kubectl exec -it app cat /data/out.txt
4. Cleanup resources:
```
kubectl delete -f specs/
```
```

0 comments on commit 0c6b853

Please sign in to comment.