Applying Default Limits to Deployments
When you have set default resource limits for a namespace using the LimitRange
resource, those limits will be automatically applied to any pods created in that namespace, including pods created by Deployments.
Deploying an Application with Default Limits
Let's deploy a simple Nginx application in a namespace with default resource limits:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
namespace: my-namespace
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-container
image: nginx
In this example, the Deployment doesn't specify any resource limits or requests. However, since we have a LimitRange
resource configured in the my-namespace
namespace, the pods created by this Deployment will automatically have the default resource limits and requests applied.
Verifying Default Limits on Deployments
You can verify the default resource limits by inspecting the pods created by the Deployment:
## List the pods in the namespace
kubectl get pods -n my-namespace
## Inspect the resource requirements of a pod
kubectl get pod my-pod-123 -n my-namespace -o yaml
The output will show that the pod has the default resource limits and requests applied, even though they were not specified in the Deployment manifest.
By using default resource limits, you can ensure that all pods in a namespace have a consistent set of resource constraints, making it easier to manage and monitor resource usage across your Kubernetes cluster.