Applying and Verifying LimitRange
Applying LimitRange
To apply a LimitRange to your Kubernetes cluster, you can use the kubectl create
command:
kubectl create -f limit-range.yaml
Where limit-range.yaml
is the file containing the LimitRange configuration.
Verifying LimitRange
After applying the LimitRange, you can verify that it has been applied correctly by checking the LimitRange object:
kubectl get limitrange
This will display the LimitRange objects in your cluster, including the one you just created.
You can also verify the LimitRange settings for a specific namespace:
kubectl describe limitrange -n <namespace>
Replace <namespace>
with the name of the namespace you want to check.
Applying LimitRange to a Pod
Once the LimitRange is applied to the cluster, it will automatically apply the default limits and requests to any pod created in the namespace. You can verify this by creating a pod and checking its resource requirements:
kubectl run nginx --image=nginx --namespace=default
kubectl describe pod nginx -n default
The pod description will show the default CPU and memory limits and requests applied by the LimitRange.
Overriding LimitRange Settings
If you need to override the default limits and requests set by the LimitRange, you can do so by explicitly setting the resource requirements in the pod specification:
apiVersion: v1
kind: Pod
metadata:
name: nginx-overridden
spec:
containers:
- name: nginx
image: nginx
resources:
limits:
cpu: 1
memory: 1Gi
requests:
cpu: 500m
memory: 512Mi
This pod will use the specified resource limits and requests, overriding the defaults set by the LimitRange.