Scheduling pods with a limit range #
A limit range schedule policy can be used in a KWOK cluster.
Prerequisites #
- KWOK must be installed on the machine. See installation.
- Install kubectl
Create cluster #
kwokctl create cluster
View clusters #
This ensures that the cluster was created successfully.
kwokctl get clusters
Create nodes #
kwokctl scale node --replicas 1
Create a resource limit #
limit-range.yaml
apiVersion: v1
kind: LimitRange
metadata:
name: cpu-resource-constraint
spec:
limits:
- max:
cpu: 500m
min:
cpu: 100m
type: Container
kubectl apply -f limit-range.yaml
Confirm the limit has the required values #
kubectl describe limitranges cpu-resource-constraint
Name: cpu-resource-constraint
Namespace: default
Type Resource Min Max Default Request Default Limit Max Limit/Request Ratio
---- -------- --- --- --------------- ------------- -----------------------
Container cpu 100m 1 500m 500m -
Deploy a pod above the resource limit #
- Pod specification:
- CPU Request: 700m
pod-beyond-limit.yaml
apiVersion: v1
kind: Pod
metadata:
name: pod-beyond-limit
namespace: default
spec:
containers:
- name: fake-container
image: fake-image
ports:
- containerPort: 80
resources:
requests:
cpu: 700m
kubectl create -f pod-beyond-limit.yaml
Notice the error Invalid value: "700m": must be less than or equal to cpu limit of 500m
Deploy a pod within the resource limit #
- Pod specification:
- CPU Request: 400m
pod-within-limit.yaml
apiVersion: v1
kind: Pod
metadata:
name: pod-within-limit
namespace: default
spec:
containers:
- name: fake-container
image: fake-image
ports:
- containerPort: 80
resources:
requests:
cpu: 400m
kubectl apply -f pod-within-limit.yaml
Confirm that the pod is running #
kubectl get pod
NAME READY STATUS RESTARTS AGE
pod-within-limit 1/1 Running 0 10s
Delete the cluster #
kwokctl delete cluster
Conclusion #
This example demonstrates how to use KWOK to simulate a scheduling scenario based on setting a limit range policy.