mirror of https://github.com/k3s-io/k3s
279 lines
9.1 KiB
Markdown
279 lines
9.1 KiB
Markdown
![]() |
<!-- BEGIN MUNGE: UNVERSIONED_WARNING -->
|
||
|
|
||
|
<!-- BEGIN STRIP_FOR_RELEASE -->
|
||
|
|
||
|
<img src="http://kubernetes.io/kubernetes/img/warning.png" alt="WARNING"
|
||
|
width="25" height="25">
|
||
|
<img src="http://kubernetes.io/kubernetes/img/warning.png" alt="WARNING"
|
||
|
width="25" height="25">
|
||
|
<img src="http://kubernetes.io/kubernetes/img/warning.png" alt="WARNING"
|
||
|
width="25" height="25">
|
||
|
<img src="http://kubernetes.io/kubernetes/img/warning.png" alt="WARNING"
|
||
|
width="25" height="25">
|
||
|
<img src="http://kubernetes.io/kubernetes/img/warning.png" alt="WARNING"
|
||
|
width="25" height="25">
|
||
|
|
||
|
<h2>PLEASE NOTE: This document applies to the HEAD of the source tree</h2>
|
||
|
|
||
|
If you are using a released version of Kubernetes, you should
|
||
|
refer to the docs that go with that version.
|
||
|
|
||
|
Documentation for other releases can be found at
|
||
|
[releases.k8s.io](http://releases.k8s.io).
|
||
|
</strong>
|
||
|
--
|
||
|
|
||
|
<!-- END STRIP_FOR_RELEASE -->
|
||
|
|
||
|
<!-- END MUNGE: UNVERSIONED_WARNING -->
|
||
|
|
||
|
# Dell EMC ScaleIO Volume Plugin for Kubernetes
|
||
|
|
||
|
This document shows how to configure Kubernetes resources to consume storage from volumes hosted on ScaleIO cluster.
|
||
|
|
||
|
## Pre-Requisites
|
||
|
|
||
|
* Kubernetes ver 1.6 or later
|
||
|
* ScaleIO ver 2.0 or later
|
||
|
* A ScaleIO cluster with an API gateway
|
||
|
* ScaleIO SDC binary installed/configured on each Kubernetes node that will consume storage
|
||
|
|
||
|
## ScaleIO Setup
|
||
|
|
||
|
This document assumes you are familiar with ScaleIO and have a cluster ready to go. If you are *not familiar* with ScaleIO, please review *Learn how to setup a 3-node* [ScaleIO cluster on Vagrant](https://github.com/codedellemc/labs/tree/master/setup-scaleio-vagrant) and see *General instructions on* [setting up ScaleIO](https://www.emc.com/products-solutions/trial-software-download/scaleio.htm)
|
||
|
|
||
|
For this demonstration, ensure the followings:
|
||
|
|
||
|
- the ScaleIO `SDC` component is installed and properly configured on all Kubernetes nodes where deployed pods will consume ScaleIO-backed volumes.
|
||
|
- You have a configured ScaleIO gateway that is accessible from the Kubernetes nodes.
|
||
|
|
||
|
## Deploy Kubernetes Secret for ScaleIO
|
||
|
|
||
|
The ScaleIO plugin uses Kubernetes Secret object to store the `username` and `password` credentials used to connect to the ScaleIO gateway API server. In this step, let us create a secret object to save the data. To avoid storing secrets in as clear text, let us encode the ScaleIO credentials as `base64` using the following steps.
|
||
|
|
||
|
```
|
||
|
$> echo -n "siouser" | base64
|
||
|
c2lvdXNlcg==
|
||
|
$> echo -n "sc@l3I0" | base64
|
||
|
c2NAbDNJMA==
|
||
|
```
|
||
|
The previous will generate `base64-encoded` values for the username and password. Remember to generate the credentials for your own environment (not the username/password shown above) . Next, create a secret file, with the encoded values from above, as shown in the following.
|
||
|
|
||
|
File: [secret.yaml](secret.yaml)
|
||
|
|
||
|
```
|
||
|
apiVersion: v1
|
||
|
kind: Secret
|
||
|
metadata:
|
||
|
name: sio-secret
|
||
|
type: kubernetes.io/scaleio
|
||
|
data:
|
||
|
username: c2lvdXNlcg==
|
||
|
password: c2NAbDNJMA==
|
||
|
```
|
||
|
|
||
|
Notice the name of the secret specified above as `sio-secret`. It will be referred in other YAML files. Next, deploy the secret.
|
||
|
|
||
|
```
|
||
|
$ kubectl create -f ./examples/volumes/scaleio/secret.yaml
|
||
|
```
|
||
|
|
||
|
## Deploying Pods with Persistent Volumes
|
||
|
|
||
|
The following example shows how the ScaleIO volume plugin for Kubernetes automatically attach, format, and mount a volume for a deployed pod. This approach requires an existing ScaleIO volume.
|
||
|
|
||
|
### Create Volume
|
||
|
|
||
|
Static persistent volumes require that the volume, to be consumed by the pod, be already created in ScaleIO. You can use your ScaleIO tooling to create a new volume or use the name of a volume that already exists in ScaleIO. For this demo, we assume there's a volume named `vol-0`. If you want to use an existing volume, ensure its name is reflected properly in the `volumeName` attribute below.
|
||
|
|
||
|
### Deploy Pod YAML
|
||
|
|
||
|
Create a pod YAML file that declares the volume (above) to be used.
|
||
|
|
||
|
File: [pod.yaml](pod.yaml)
|
||
|
|
||
|
```
|
||
|
apiVersion: v1
|
||
|
kind: Pod
|
||
|
metadata:
|
||
|
name: pod-0
|
||
|
spec:
|
||
|
containers:
|
||
|
- image: gcr.io/google_containers/test-webserver
|
||
|
name: pod-0
|
||
|
volumeMounts:
|
||
|
- mountPath: /test-pd
|
||
|
name: vol-0
|
||
|
volumes:
|
||
|
- name: vol-0
|
||
|
scaleIO:
|
||
|
gateway: https://localhost:443/api
|
||
|
system: scaleio
|
||
|
volumeName: vol-0
|
||
|
secretRef:
|
||
|
name: sio-secret
|
||
|
fsType: xfs
|
||
|
```
|
||
|
|
||
|
Notice the followings in the previous YAML:
|
||
|
|
||
|
- Update the `gatewway` to point to your ScaleIO gateway endpoint.
|
||
|
- The `volumeName` attribute refers to the name of an existing volume in ScaleIO.
|
||
|
- The `secretRef` attribute references the name of the secret object deployed earlier.
|
||
|
|
||
|
Next, deploy the pod.
|
||
|
|
||
|
```
|
||
|
$> kubectl create -f examples/volumes/scaleio/pod.yaml
|
||
|
```
|
||
|
You can verify the pod:
|
||
|
```
|
||
|
$> kubectl get pod
|
||
|
NAME READY STATUS RESTARTS AGE
|
||
|
pod-0 1/1 Running 0 33s
|
||
|
```
|
||
|
Or for more detail, use
|
||
|
```
|
||
|
kubectl describe pod pod-0
|
||
|
```
|
||
|
You can see the attached/mapped volume on the node:
|
||
|
```
|
||
|
$> lsblk
|
||
|
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
|
||
|
...
|
||
|
scinia 252:0 0 8G 0 disk /var/lib/kubelet/pods/135986c7-dcb7-11e6-9fbf-080027c990a7/volumes/kubernetes.io~scaleio/vol-0
|
||
|
```
|
||
|
|
||
|
## StorageClass and Dynamic Provisioning
|
||
|
|
||
|
In this example, we will see how the ScaleIO volume plugin can automatically provision a new volume as described in a `StorageClass`.
|
||
|
|
||
|
### StorageClass
|
||
|
|
||
|
Define a new `StorageClass` as shown in the following YAML.
|
||
|
|
||
|
File [sc.yaml](sc.yaml)
|
||
|
|
||
|
```
|
||
|
kind: StorageClass
|
||
|
apiVersion: storage.k8s.io/v1beta1
|
||
|
metadata:
|
||
|
name: sio-small
|
||
|
provisioner: kubernetes.io/scaleio
|
||
|
parameters:
|
||
|
gateway: https://localhost:443/api
|
||
|
system: scaleio
|
||
|
protectionDomain: default
|
||
|
secretRef: sio-secret
|
||
|
fsType: xfs
|
||
|
```
|
||
|
|
||
|
Note the followings:
|
||
|
|
||
|
- The `name` attribute is set to `sio-small` . It will be referenced later.
|
||
|
- The `provisioner` attribute is set to `kubernetes.io/scaleio` to trigger the ScaleIO plugin.
|
||
|
- The use of the `parameters:` section in the yaml for configurations.
|
||
|
- The `secretRef` attribute matches the name of the Secret object created earlier.
|
||
|
|
||
|
Next, deploy the storage class file.
|
||
|
|
||
|
```
|
||
|
$> kubectl create -f examples/volumes/scaleio/sc.yaml
|
||
|
|
||
|
$> kubectl get sc
|
||
|
NAME TYPE
|
||
|
sio-small kubernetes.io/scaleio
|
||
|
```
|
||
|
|
||
|
### PVC for the StorageClass
|
||
|
|
||
|
The next step is to define/deploy a `PeristentVolumeClaim` that will use the StorageClass.
|
||
|
|
||
|
File [sc-pvc.yaml](sc-pvc.yaml)
|
||
|
|
||
|
```
|
||
|
kind: PersistentVolumeClaim
|
||
|
apiVersion: v1
|
||
|
metadata:
|
||
|
name: pvc-sio-small
|
||
|
annotations:
|
||
|
volume.beta.kubernetes.io/storage-class: sio-small
|
||
|
spec:
|
||
|
accessModes:
|
||
|
- ReadWriteOnce
|
||
|
resources:
|
||
|
requests:
|
||
|
storage: 10Gi
|
||
|
```
|
||
|
|
||
|
Note the `annotations:` entry which specifies annotation `volume.beta.kubernetes.io/storage-class: sio-small` which references the name of the storage class defined earlier.
|
||
|
|
||
|
Next, we deploy PVC file for the storage class. This step will cause the Kubernetes ScaleIO plugin to create the volume in the storage system.
|
||
|
```
|
||
|
$> kubectl create -f examples/volumes/scaleio/sc-pvc.yaml
|
||
|
```
|
||
|
You verify that a new volume created in the ScaleIO dashboard. You can also verify the newly created volume as follows.
|
||
|
```
|
||
|
kubectl get pvc
|
||
|
NAME STATUS VOLUME CAPACITY ACCESSMODES AGE
|
||
|
pvc-sio-small Bound pvc-5fc78518-dcae-11e6-a263-080027c990a7 10Gi RWO 1h
|
||
|
```
|
||
|
|
||
|
###Pod for PVC and SC
|
||
|
At this point, the volume is created (by the claim) in the storage system. To use it, we must define a pod that references the volume as done in this YAML.
|
||
|
|
||
|
File [pod-sc-pvc.yaml](pod-sc-pvc.yaml)
|
||
|
|
||
|
```
|
||
|
kind: Pod
|
||
|
apiVersion: v1
|
||
|
metadata:
|
||
|
name: pod-sio-small
|
||
|
spec:
|
||
|
containers:
|
||
|
- name: pod-sio-small-container
|
||
|
image: gcr.io/google_containers/test-webserver
|
||
|
volumeMounts:
|
||
|
- mountPath: /test
|
||
|
name: test-data
|
||
|
volumes:
|
||
|
- name: test-data
|
||
|
persistentVolumeClaim:
|
||
|
claimName: pvc-sio-small
|
||
|
```
|
||
|
|
||
|
Notice that the `claimName:` attribute refers to the name of the PVC defined and deployed earlier. Next, let us deploy the file.
|
||
|
|
||
|
```
|
||
|
$> kubectl create -f examples/volumes/scaleio/pod-sc-pvc.yaml
|
||
|
```
|
||
|
We can now verify that the new pod is deployed OK.
|
||
|
```
|
||
|
kubectl get pod
|
||
|
NAME READY STATUS RESTARTS AGE
|
||
|
pod-0 1/1 Running 0 23m
|
||
|
pod-sio-small 1/1 Running 0 5s
|
||
|
```
|
||
|
You can use the ScaleIO dashboard to verify that the new volume has one attachment. You can verify the volume information for the pod:
|
||
|
```
|
||
|
$> kubectl describe pod pod-sio-small
|
||
|
...
|
||
|
Volumes:
|
||
|
test-data:
|
||
|
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
|
||
|
ClaimName: pvc-sio-small
|
||
|
ReadOnly: false
|
||
|
...
|
||
|
```
|
||
|
Lastly, you can see the volume's attachment on the Kubernetes node:
|
||
|
```
|
||
|
$> lsblk
|
||
|
...
|
||
|
scinia 252:0 0 8G 0 disk /var/lib/kubelet/pods/135986c7-dcb7-11e6-9fbf-080027c990a7/volumes/kubernetes.io~scaleio/vol-0
|
||
|
scinib 252:16 0 16G 0 disk /var/lib/kubelet/pods/62db442e-dcba-11e6-9fbf-080027c990a7/volumes/kubernetes.io~scaleio/sio-5fc9154ddcae11e68db708002
|
||
|
|
||
|
```
|
||
|
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
|
||
|
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/examples/volumes/scaleio/README.md?pixel)]()
|
||
|
<!-- END MUNGE: GENERATED_ANALYTICS -->
|