Skip to content

Latest commit

 

History

History
 
 

kubernetes

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Kubernetes examples

You can found in this directory some examples about how to use the Scaleway CSI driver inside Kubernetes.

It will cover Persistent Volumes/Persistent Volume Claim (PV/PVC), Storage Class and Volume Snapshots

If a StorageClass is not provided in the examples, the scw-bssd storage class will be used.

PVC & Deployment

We will create a PersistentVolumeClaim and use it as a volume inside the pod of a deployment, to store nginx's logs. First, we will create a 3Gi volume:

$ kubectl apply -f pvc-deployment/pvc.yaml

Now we can create the deployment that will use this volume:

$ kubectl apply -f pvc-deployment/deployment.yaml

Raw Block Volumes

We will create a block volume and make it available in the pod as a raw block device. In order to do so, volumeMode must be set to Block. First, create the volume:

$ kubectl apply -f raw-volume/pvc.yaml

Now we can create a pod that will use this raw volume. In order to do so, volumesDevices must be used, instead of the traditional volumeMounts:

$ kubectl apply -f raw-volume/pod.yaml

You can now exec into the container and use the volume as a classic block device:

$ kubectl exec -it my-awesome-block-volume-app sh
/ # ls -al /dev/xvda
brw-rw----    1 root     disk        8,  32 Mar 23 12:34 /dev/xvda
/ # dd if=/dev/zero of=/dev/xvda bs=1024k count=100
100+0 records in
100+0 records out
104857600 bytes (100.0MB) copied, 0.043702 seconds, 2.2GB/s

Importing existing Scaleway volumes

If you have an already existing volume, with the ID 11111111-1111-1111-111111111111 in the zone fr-par-1, you can import it by creating the following PV:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: test-pv
spec:
  capacity:
    storage: 5Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  storageClassName: scw-bssd
  csi:
    driver: csi.scaleway.com
    volumeHandle: fr-par-1/11111111-1111-1111-111111111111
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: topology.csi.scaleway.com/zone
          operator: In
          values:
          - fr-par-1

Once the PV is created, create a PVC with the same attributes (here scw-bssd as storage class and a size of 5Gi):

$ kubectl apply -f importing/pvc.yaml

And finally create a pod that uses this volume:

$ kubectl apply -f importing/pod.yaml

Volume Snapshots

In Kubernetes, it is possible to create snapshots via the VolumeSnapshot object.

Volumes can be snapshotted, and restored from snapshots. First let's create a PVC:

$ kubctl apply -f snapshots/pvc.yaml

We can now snapshot it:

$ kubectl apply -f snapshots/snapshot.yaml

And it should be marked as ready:

$ kubectl get volumesnapshot.snapshot.storage.k8s.io
NAME          READYTOUSE   SOURCEPVC                       SOURCESNAPSHOTCONTENT   RESTORESIZE   SNAPSHOTCLASS   SNAPSHOTCONTENT                                    CREATIONTIME   AGE
my-snapshot   true         my-soon-to-be-snapshotted-pvc                           5Gi           scw-snapshot    snapcontent-7146128a-c9f2-4050-856f-8ae1590eb436   113s           114s

When ready, you can create a new PVC from this snapshot:

$ kubectl apply -f snapshots/restored-snapshot.yaml

Importing snapshots

It is also possible, as for the volumes, to import snapshots. Let's say you have a snapshot in fr-par-1 with the ID 11111111-1111-1111-111111111111. You must first import the VolumeSnapshotContent as followed:

apiVersion: snapshot.storage.k8s.io/v1beta1
kind: VolumeSnapshotContent
metadata:
  name: my-imported-snapshot-content
spec:
  volumeSnapshotRef:
    kind: VolumeSnapshot
    name: my-imported-snapshot
  source:
    snapshotHandle: fr-par-1/11111111-1111-1111-111111111111
  driver: csi.scaleway.com
  volumeSnapshotClassName: scw-snapshot
  deletionPolicy: Retain

Once it's done, we can now create the VolumeSnapshot with:

apiVersion: snapshot.storage.k8s.io/v1beta1
kind: VolumeSnapshot
metadata:
  name: my-imported-snapshot
spec:
  volumeSnapshotClassName: scw-snapshot
  source:
    volumeSnapshotContentName: my-imported-snapshot-content

And now, it's available to use:

$ kubectl get volumesnapshot.snapshot.storage.k8s.io 
NAME                   READYTOUSE   SOURCEPVC                       SOURCESNAPSHOTCONTENT          RESTORESIZE   SNAPSHOTCLASS   SNAPSHOTCONTENT                                    CREATIONTIME   AGE
my-imported-snapshot   true                                         my-imported-snapshot-content   3Gi           scw-snapshot    my-imported-snapshot-content                       46d            3m32s

Different StorageClass

StorageClasses offer a way to easily create different types of Volumes.

In the installation guide, a basic storage class is deployed: scw-bssd that will provision standard Scaleway Block Volumes. We will see here how to customize different storage class. The provisioner will always be csi.scaleway.com.

Set a default storage class

In order to have a default storage class (ie not having to specify the storageClassName for each PVC), you must add the storageclass.kubernetes.io/is-default-class: "true" annotation to the storage class:

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: my-default-storage-class
  annotations:
    storageclass.kubernetes.io/is-default-class: "true"
provisioner: csi.scaleway.com 
reclaimPolicy: Delete

Choose the filesystem type

In order to change the filesystem type used to format the volume (it's ext4 by default), you must add the csi.storage.k8s.io/fstype parameter to the storage class:

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: my-ext3-storage-class
provisioner: csi.scaleway.com 
reclaimPolicy: Delete
parameters:
  csi.storage.k8s.io/fstype: ext3

Choose the type of Scaleway Block Volume

When the new type of Scaleway Block Volume will be available, let's say it's called b_ssd+, you will need to add the type parameter to the storage class:

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: my-bssdplus-storage-class
provisioner: csi.scaleway.com 
reclaimPolicy: Delete
parameters:
  type: b_ssd+

Specify in which zone the volumes are going to be created

By default, the Scaleway CSI plugin uses the SCW_DEFAULT_ZONE environment variable to get the zone where the volumes will be provisioned. If you want to override this value, you must use the allowedTopologies field of the storage class to specify a zone:

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: my-ams-storage-class
provisioner: csi.scaleway.com 
reclaimPolicy: Delete
allowedTopologies:
- matchLabelExpressions:
  - key: topology.csi.scaleway.com/zone
    values:
    - nl-ams-1