Use a Local Disk Through LocalVolume Provisioner in a Kubernetes Cluster

Introduction

Alibaba Cloud provides local disk configurations for some Elastic Compute Service ECS instances. Local disks have the advantages of low latency, high random IOPS, high throughput, and high cost effectiveness, and has great advantages in some applications with high performance requirements.

  • HostPath: The volume itself does not contain scheduling information. If you want to fix each pod on a node, you need to configure scheduling information, such as nodeSelector, for the pod;
  • LocalVolume: The volume itself contains scheduling information, and the pods using this volume will be fixed on a specific node, which can ensure data continuity.
  • Use LocalVolume Provisioner to automatically create LocalVolume, and the PV comes with the information about the node to which it belongs.
  • Create a PVC to consume LocalVolume. Pods using this PVC will be scheduled to the node specified by the PV.

How Provisioner Works

1) Introduction to Local Disks:

To learn more about ECS local disks, refer to Local disks

2) Mounting Principle:

Deploy Alibaba LocalVolume Provisioner

1) Create ConfigMap:

The configuration parameters of Provisioner are placed in the ConfigMap, provisioner-config:

apiVersion: v1
kind: ConfigMap
metadata:
name: local-provisioner-config
namespace: kube-system
data:
storageClassMap: |
local-volume:
vendor: alibabacloud
hostDir: /mnt/disks
mountDir: /mnt/disks
blockCleanerCommand:
- "/scripts/shred.sh"
- "2"
volumeMode: Filesystem
fsType: ext4
deviceStartWith: vdb
mkFSOptions: ""
mountOptions: "nodelalloc"

2) Create StorageClass

LocalVolume StorageClass does not actually go to Provisioner PV, but is used to define configuration details, such as reclaimPolicy and volumeBindingMode.

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: local-volume
provisioner: kubernetes.io/no-provisioner
reclaimPolicy: Retain
volumeBindingMode: WaitForFirstConsumer

3) Create a Provisioner Service

For deployment through Daemonset, set hostPID and hostNetwork to true;

apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: local-volume-provisioner
namespace: kube-system
labels:
app: local-volume-provisioner
spec:
selector:
matchLabels:
app: local-volume-provisioner
template:
metadata:
labels:
app: local-volume-provisioner
spec:
hostPID: true
hostNetwork: true
serviceAccountName: admin
containers:
- image: registry.cn-hangzhou.aliyuncs.com/plugins/local-volume-provisioner:v1.12-7802d35-aliyun
imagePullPolicy: "Always"
name: provisioner
securityContext:
privileged: true
env:
- name: MY_NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: ACCESS_KEY_ID
value: ""
- name: ACCESS_KEY_SECRET
value: ""
volumeMounts:
- mountPath: /etc/provisioner/config
name: provisioner-config
readOnly: true
- mountPath: /mnt/disks
name: local
mountPropagation: "HostToContainer"
- mountPath: /etc/kubernetes
name: etc
volumes:
- name: provisioner-config
configMap:
name: local-provisioner-config
- name: local
hostPath:
path: /mnt/disks
- name: etc
hostPath:
path: /etc/kubernetes

Consume LocalVolume

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: myclaim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: local-volume
kind: Pod
apiVersion: v1
metadata:
name: mypod
spec:
containers:
- name: myfrontend
image: nginx
volumeMounts:
- mountPath: "/data"
name: mypd
volumes:
- name: mypd
persistentVolumeClaim:
claimName: myclaim

Original Source

https://www.alibabacloud.com/blog/use-a-local-disk-through-localvolume-provisioner-in-a-kubernetes-cluster_594930?spm=a2c41.13057465.0.0

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Alibaba Cloud

4.97K Followers

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com