local-path-provisioner如何添加配额限制

2025-05-20  本文已影响0人  wwq2020

背景

使用local-path-provisioner来供应local pv,但是local-path-provisioner仓库内没有提供local pv的配额限制方法
所以需要修改他的configmap中的配置

修改

yourimage内需要带xfs_quota命令
yourpath为local pv在host侧的目录
yourmountpoint为local pv在host侧目录对应的挂载点

apiVersion: v1
data:
config.json: |-
{
"nodePathMap":[
{
"node":"DEFAULT_PATH_FOR_NON_LISTED_NODES",
"paths":["/yourpath"]
}
]
}
helperPod.yaml: |-
apiVersion: v1
kind: Pod
metadata:
name: helper-pod
spec:
priorityClassName: system-node-critical
tolerations:
- key: node.kubernetes.io/disk-pressure
operator: Exists
effect: NoSchedule
containers:
- name: helper-pod
securityContext:
privileged: true
image: yourimage
imagePullPolicy: IfNotPresent
volumeMounts:
- name: projects
mountPath: /etc/projects
- name: projid
mountPath: /etc/projid
- name: dev
mountPath: /dev
- name: yourmountpoint
mountPath: /yourmountpoint
volumes:
- hostPath:
path: /etc/projects
type: FileOrCreate
name: projects
- hostPath:
path: /etc/projid
type: FileOrCreate
name: projid
- hostPath:
path: /dev
type: Directory
name: dev
- hostPath:
path: /yourmountpoint
type: Directory
name: yourmountpoint
setup: |-
#!/bin/sh
set -e
xfsPath="/yourmountpoint"
pvcName=(basename "VOL_DIR")
mkdir -p "VOL_DIR" type=`stat -f -c %T{xfsPath}if [ ${type} = 'xfs' ]; then echo "support xfs quota" exec 6>/tmp/local-path.lock flock -nx 6 project=cat /etc/projects | tail -n 1id=echo {project%:*}` if [ !{project} ]; then
id=1
else
id=((id+1)) fi echo "{id}:{VOL_DIR}" >> /etc/projects sync -d /etc/projects echo "{pvcName}:{id}" >> /etc/projid sync -d /etc/projid flock -u 6 xfs_quota -x -c "project -s{pvcName}"
xfs_quota -x -c "limit -p bsoft={VOL_SIZE_BYTES} bhard={VOL_SIZE_BYTES} {pvcName}"{xfsPath}
xfs_quota -x -c "report -pbih" {xfsPath} fi teardown: |- #!/bin/sh set -e xfsPath="/yourmountpoint" pvcName=(basename "VOL_DIR") type=`stat -f -c %T{xfsPath}`
if [ {type} = 'xfs' ]; then echo "support xfs quota" xfs_quota -x -c "limit -p bsoft=0 bhard=0{pvcName}" {xfsPath} fi rm -rf "VOL_DIR"
if [ {type} = 'xfs' ]; then echo "(sed "/{pvcName}/d" /etc/projects)" > /etc/projects sync -d /etc/projects echo "(sed "/{pvcName}/d" /etc/projid)" > /etc/projid sync -d /etc/projid xfs_quota -x -c "report -pbih"{xfsPath}
fi
kind: ConfigMap
metadata:
name: local-path-config
namespace: local-path-storage

上一篇 下一篇

猜你喜欢

热点阅读