Volume size limiting¶
Volume size limiting is a configuration mechanism in Kubernetes that allows administrators to define a maximum amount of storage a specific volume can consume.^[400-devops__06-Kubernetes__k8s-ithelp__Day17__README.md]
In the context of emptyDir volumes, this is managed via the sizeLimit field within the spec.volumes.emptyDir nested configuration.^[400-devops__06-Kubernetes__k8s-ithelp__Day17__README.md]
Default behavior¶
By default, the sizeLimit is set to nil, which implies that no storage quota is enforced for the volume.^[400-devops__06-Kubernetes__k8s-ithelp__Day17__README.md]
Usage with Memory medium¶
While optional for the default storage medium, setting a sizeLimit is strongly recommended when the volume's medium is set to Memory.^[400-devops__06-Kubernetes__k8s-ithelp__Day17__README.md]
When medium is configured as Memory, the volume utilizes a RAM-backed temporary file system (tmpfs).^[400-devops__06-Kubernetes__k8s-ithelp__Day17__README.md] Because this storage type relies on system memory, which is a more finite resource than disk space, defining an explicit limit helps prevent the container from consuming excessive node resources.^[400-devops__06-Kubernetes__k8s-ithelp__Day17__README.md]
Example configuration¶
The following manifest demonstrates how to restrict an in-memory volume to 256 MiB:^[400-devops__06-Kubernetes__k8s-ithelp__Day17__README.md]
apiVersion: v1
kind: [Pod](<./pod.md>)
metadata:
name: emptydir-memory-pod
spec:
volumes:
- name: html
emptyDir:
medium: Memory # Use RAM for storage
sizeLimit: 256Mi # Enforce a 256 MiB limit
containers:
- name: nginx
image: nginx:latest
volumeMounts:
- name: html
mountPath: /usr/share/nginx/html
Related concepts¶
- [[Kubernetes Volumes]]
- [[emptyDir]]
- Pod
Sources¶
^[400-devops__06-Kubernetes__k8s-ithelp__Day17__README.md]