Resource Limits
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 3
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
resources:
limits:
cpu: "1"
memory: "512Mi"
ports:
- containerPort: 80
```plaintext
In this example, the `resources` field is used to set the resource limits for the container. The `limits` field specifies the maximum amount of CPU and memory that the container is allowed to use. In this case, the container is limited to 1 CPU and 512 MB of memory.
2. Setting CPU, memory, and GPU resource limits for a Deployment:
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: ml-deployment
spec:
selector:
matchLabels:
app: ml
replicas: 1
template:
metadata:
labels:
app: ml
spec:
containers:
- name: ml
image: ml:latest
resources:
limits:
cpu: "2"
memory: "8Gi"
nvidia.com/gpu: "1"
```plaintext
In this example, the `resources` field is used to set the CPU, memory, and GPU resource limits for the container. The `limits` field specifies the maximum amount of CPU and memory that the container is allowed to use, as well as the number of GPUs that can be used. In this case, the container is limited to 2 CPUs, 8 GB of memory, and 1 GPU.
3. Setting CPU and memory resource limits for a Deployment using shorthand notation:
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: app-deployment
spec:
selector:
matchLabels:
app: myapp
replicas: 2
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: myapp:latest
resources:
limits:
cpu: 2
memory: 4Gi
ports:
- containerPort: 80
```plaintext
In this example, the shorthand notation is used to set the resource limits for the container. The `limits` field specifies the maximum amount of CPU and memory that the container is allowed to use. In this case, the container is limited to 2 CPUs and 4 GB of memory.
Overall, setting resource limits for Kubernetes Deployments is an essential task that helps ensure that the Kubernetes cluster operates smoothly and efficiently. By setting resource limits, you can prevent individual containers or pods from monopolizing the resources available in the cluster and ensure that all applications running in the cluster have access to the resources they need to function effectively.
Last updated