我创建了一个持久卷声明,20Mi storage limits
但17 Mi storage requests
我可以在文件夹中上传一个 50 Mi 的hostPath
文件。但我想要的是限制文件夹内容的大小。如果文件夹中包含超过 20Mi 的内容,那么 Kubernetes 应该说它不允许新文件。
持续音量:
apiVersion: v1
kind: PersistentVolume
metadata:
name: example-pv
namespace: limit-range
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: local-storage
hostPath:
path: /home/me/kubernetes/web
type: DirectoryOrCreate
持久卷声明:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc
namespace: limit-range
spec:
storageClassName: local-storage
accessModes:
- ReadWriteOnce
resources:
limits:
storage: 20Mi
requests:
storage: 17Mi
部署:
apiVersion: apps/v1
kind: Deployment
metadata:
name: upload-preview-2
namespace: limit-range
spec:
selector:
matchLabels:
app: upload-preview-2
template:
metadata:
labels:
app: upload-preview-2
spec:
containers:
- image: upload-preview:latest
imagePullPolicy: Never
name: web
ports:
- containerPort: 80
volumeMounts:
- mountPath: /var/www/html/web
name: localpath
subPath: dev
volumes:
- name: localpath
persistentVolumeClaim:
claimName: pvc
使用这种配置,它并没有给我我所期望的。所以我尝试Limit range
了Quota
但仍然没有预期的行为。
限制范围:
apiVersion: v1 kind: LimitRange metadata: name: storagelimits namespace: limit-range spec: limits:
- type: PersistentVolumeClaim
max:
storage: 18Mi
min:
storage: 10Mi
配额:
apiVersion: v1
kind: ResourceQuota
metadata:
name: storagequota
namespace: limit-range
spec:
hard:
persistentvolumeclaims: "5"
requests.storage: "18Mi"
我试过kubectl describe quota -n limit-range
了,结果是:
Name: storagequota
Namespace: limit-range
Resource Used Hard
-------- ---- ----
persistentvolumeclaims 1 5
requests.storage 17Mi 18Mi
我的想法是它可能不起作用,因为我正在使用hostPath
.