Using encrypted disks for persistent volumes
Managed Service for Kubernetes supports the use of Compute Cloud disks encrypted with custom Yandex Key Management Service symmetric keys for persistent volumes.
Note
To use encrypted disks, the cloud service account assigned to your Managed Service for Kubernetes cluster must have the kms.keys.encrypterDecrypter
role for the key or folder.
You can use encrypted disks for both static and dynamic preparation of persistent volumes.
Static volume provisioning
-
Create a symmetric key in Key Management Service.
-
Create an encrypted disk using the key you created earlier.
Save the ID of the disk. You will need it later.
-
Assign the
kms.keys.encrypterDecrypter
role for a key or folder to the cloud service account of the Managed Service for Kubernetes cluster. -
Prepare a persistent volume. In the manifest of the
PersistentVolume
object, specify the ID of the created disk in thespec:csi:volumeHandle
parameter.
Dynamic volume provisioning
-
Create a symmetric key in Key Management Service.
Save the ID of the key. You will need it later.
-
Assign the
kms.keys.encrypterDecrypter
role for a key or folder to the cloud service account of the Managed Service for Kubernetes cluster. -
Install kubect
and configure it to work with the new cluster. -
In the
encrypted-storage-class.yaml
file, create a manifest for the new storage class:kind: StorageClass apiVersion: storage.k8s.io/v1 metadata: name: <storage_class_name> provisioner: disk-csi-driver.mks.ycloud.io volumeBindingMode: WaitForFirstConsumer parameters: type: <disk_type> csi.storage.k8s.io/fstype: ext4 kmsKeyId: <symmetric_key_ID> allowVolumeExpansion: true reclaimPolicy: Delete
Where:
metadata:name
: Random storage class name.parameters:type
: Disk type in Compute Cloud. The possible values are:network-ssd
: Network SSD.network-hdd
: Network HDD.network-ssd-nonreplicated
: Non-replicated SSD.network-ssd-io-m3
: Ultra high-speed network storage with three replicas (SSD).
parameters:kmsKeyId
: Symmetric key ID.
-
Create a storage class:
kubectl apply -f encrypted-storage-class.yaml
-
In the
encrypted-pvc.yaml
file, create a manifest for the newPersistentVolumeClaim
object:apiVersion: v1 kind: PersistentVolumeClaim metadata: name: <PVC_name> spec: accessModes: - ReadWriteOnce storageClassName: <storage_class_name> resources: requests: storage: 4Gi
Where:
metadata:name
: Random name for thePersistentVolumeClaim
object.spec:storageClassName
: Name of the storage class created earlier.
-
Create the
PersistentVolumeClaim
object:kubectl apply -f encrypted-pvc.yaml
-
In the
pod-with-encrypted-pvc.yaml
file, create a manifest for the pod with a dynamically prepared persistent volume:apiVersion: v1 kind: Pod metadata: name: <pod_name> spec: containers: - name: app image: ubuntu command: ["/bin/sh"] args: ["-c", "while true; do echo $(date -u) >> /data/out.txt; sleep 5; done"] volumeMounts: - name: persistent-storage mountPath: /data volumes: - name: persistent-storage persistentVolumeClaim: claimName: <PVC_name>
Where:
metadata:name
: Random name for the pod.spec:volumes:persistentVolumeClaim:claimName
: Name of thePersistentVolumeClaim
object created earlier.
-
Create a pod.
kubectl apply -f pod-with-encrypted-pvc.yaml
After creating a pod in the management console
in Compute Cloud in the Disks section, a new encrypted disk will appear with thek8s-csi
prefix in the name.