Container Service for Kubernetes (ACK) provides temporary memory volumes. These volumes provide high-performance, local temporary storage for your applications.
Background information
Memory volumes provide temporary storage, but data is lost when a pod restarts.
This type of local storage is suitable for high-speed caching scenarios.
Deploy the plugin
The memory Container Storage Interface (CSI) plugin has two components: the Plugin, which mounts memory volumes, and the Provisioner, which creates memory volumes.
Note
This feature is supported only in ACK clusters that run Kubernetes 1.18 or earlier.
Deploy the CSI Memory Plugin
apiVersion: storage.k8s.io/v1beta1
kind: CSIDriver
metadata:
name: memplugin.csi.alibabacloud.com
spec:
attachRequired: false
podInfoOnMount: true
---
kind: DaemonSet
apiVersion: apps/v1
metadata:
name: csi-mem-plugin
namespace: kube-system
spec:
selector:
matchLabels:
app: csi-mem-plugin
template:
metadata:
labels:
app: csi-mem-plugin
spec:
tolerations:
- operator: Exists
serviceAccount: admin
priorityClassName: system-node-critical
hostNetwork: true
hostPID: true
containers:
- name: driver-registrar
image: registry.cn-hangzhou.aliyuncs.com/acs/csi-node-driver-registrar:v1.1.0
imagePullPolicy: Always
args:
- "--v=5"
- "--csi-address=/csi/csi.sock"
- "--kubelet-registration-path=/var/lib/kubelet/plugins/memplugin.csi.alibabacloud.com/csi.sock"
env:
- name: KUBE_NODE_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: spec.nodeName
volumeMounts:
- name: plugin-dir
mountPath: /csi
- name: registration-dir
mountPath: /registration
- name: csi-memplugin
securityContext:
privileged: true
capabilities:
add: ["SYS_ADMIN"]
allowPrivilegeEscalation: true
image: registry.cn-hangzhou.aliyuncs.com/acs/csi-plugin:v1.14.8.41-9efe2ede-aliyun
imagePullPolicy: "Always"
args :
- "--endpoint=$(CSI_ENDPOINT)"
- "--v=5"
- "--nodeid=$(KUBE_NODE_NAME)"
- "--driver=memplugin.csi.alibabacloud.com"
env:
- name: KUBE_NODE_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: spec.nodeName
- name: CSI_ENDPOINT
value: unix://var/lib/kubelet/plugins/memplugin.csi.alibabacloud.com/csi.sock
volumeMounts:
- name: pods-mount-dir
mountPath: /var/lib/kubelet
mountPropagation: "Bidirectional"
- mountPath: /dev
mountPropagation: "HostToContainer"
name: host-dev
- mountPath: /var/log/
name: host-log
volumes:
- name: plugin-dir
hostPath:
path: /var/lib/kubelet/plugins/memplugin.csi.alibabacloud.com
type: DirectoryOrCreate
- name: registration-dir
hostPath:
path: /var/lib/kubelet/plugins_registry
type: DirectoryOrCreate
- name: pods-mount-dir
hostPath:
path: /var/lib/kubelet
type: Directory
- name: host-dev
hostPath:
path: /dev
- name: host-log
hostPath:
path: /var/log/
updateStrategy:
rollingUpdate:
maxUnavailable: 10%
type: RollingUpdateDeploy the CSI Memory Provisioner
kind: Deployment
apiVersion: apps/v1
metadata:
name: csi-memprovisioner
namespace: kube-system
spec:
selector:
matchLabels:
app: csi-memprovisioner
replicas: 2
template:
metadata:
labels:
app: csi-memprovisioner
spec:
tolerations:
- operator: "Exists"
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1
preference:
matchExpressions:
- key: node-role.kubernetes.io/master
operator: Exists
priorityClassName: system-node-critical
serviceAccount: admin
hostNetwork: true
containers:
- name: csi-provisioner
image: registry.cn-hangzhou.aliyuncs.com/acs/csi-provisioner:v1.4.0-aliyun
args:
- "--provisioner=memplugin.csi.alibabacloud.com"
- "--csi-address=$(ADDRESS)"
- "--feature-gates=Topology=True"
- "--volume-name-prefix=mem"
- "--strict-topology=true"
- "--timeout=150s"
- "--enable-leader-election=true"
- "--leader-election-type=leases"
- "--retry-interval-start=500ms"
- "--v=5"
env:
- name: ADDRESS
value: /var/lib/kubelet/plugins/memplugin.csi.alibabacloud.com/csi.sock
imagePullPolicy: "Always"
volumeMounts:
- name: socket-dir
mountPath: /var/lib/kubelet/plugins/memplugin.csi.alibabacloud.com
volumes:
- name: socket-dir
hostPath:
path: /var/lib/kubelet/plugins/memplugin.csi.alibabacloud.com
type: DirectoryOrCreateExample: Use a memory volume
Use the following template to deploy a StorageClass.
apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: csi-mem provisioner: memplugin.csi.alibabacloud.com reclaimPolicy: DeleteUse the following template to create a persistent volume claim (PVC) and an application.
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: mem-pvc spec: accessModes: - ReadWriteOnce resources: requests: storage: 2Gi storageClassName: csi-mem --- apiVersion: apps/v1 kind: Deployment metadata: name: deployment-mem labels: app: nginx spec: selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/nginx:1.14.1-8.6 command: ["sh", "-c"] args: ["sleep 10000"] volumeMounts: - name: mem-pvc mountPath: "/data" volumes: - name: mem-pvc persistentVolumeClaim: claimName: mem-pvc