[Create a Namespace]
$ kubectl create namespace constraints-cpu-example

[Create the LimitRange]
$ kubectl apply -f LimitRange_1.yaml --namespace=constraints-cpu-example
$ kubectl apply -f https://k8s.io/examples/admin/resource/cpu-constraints.yaml --namespace=constraints-cpu-example

[View detailed information about the LimitRange]
$ kubectl get limitrange cpu-min-max-demo-lr --output=yaml --namespace=constraints-cpu-example
...
limits:
- default:
    cpu: 800m
  defaultRequest:
    cpu: 800m
  max:
    cpu: 800m
  min:
    cpu: 200m
  type: Container

Now whenever you create a Pod in the constraints-cpu-example namespace, Kubernetes performs these steps:-
If any container in that Pod does not specify its own CPU request and limit, the control plane assigns the default CPU request and limit to that container.
Verify that every container in that Pod specifies a CPU request that is greater than or equal to 200 millicpu.
Verify that every container in that Pod specifies a CPU limit that is less than or equal to 800 millicpu.

[Create the Pod]
$ kubectl apply -f Pod_1.yaml --namespace=constraints-cpu-example
$ kubectl apply -f https://k8s.io/examples/admin/resource/cpu-constraints-pod.yaml --namespace=constraints-cpu-example

[Verify that the Pod is running and that its container is healthy]
$ kubectl get pod constraints-cpu-demo --namespace=constraints-cpu-example

[View detailed information about the Pod]
$ kubectl get pod constraints-cpu-demo --output=yaml --namespace=constraints-cpu-example
...
resources:
  limits:
    cpu: 800m
  requests:
    cpu: 500m

[Delete the Pod]
$ kubectl delete pod constraints-cpu-demo --namespace=constraints-cpu-example


⦿ Attempt to create a Pod that exceeds the maximum CPU constraint

[Create the Pod]
$ kubectl apply -f Pod_2.yaml --namespace=constraints-cpu-example
$ kubectl apply -f https://k8s.io/examples/admin/resource/cpu-constraints-pod-2.yaml --namespace=constraints-cpu-example
Error from server (Forbidden): error when creating "examples/admin/resource/cpu-constraints-pod-2.yaml": pods "constraints-cpu-demo-2" is forbidden: maximum cpu usage per Container is 800m, but limit is 1500m.

The output shows that the Pod does not get created, because it defines an unacceptable container. 
That container is not acceptable because it specifies a CPU limit that is too large.


⦿ Attempt to create a Pod that does not meet the minimum CPU request

[Create the Pod]
$ kubectl apply -f Pod_3.yaml --namespace=constraints-cpu-example
$ kubectl apply -f https://k8s.io/examples/admin/resource/cpu-constraints-pod-3.yaml --namespace=constraints-cpu-example
Error from server (Forbidden): error when creating "examples/admin/resource/cpu-constraints-pod-3.yaml": pods "constraints-cpu-demo-3" is forbidden: minimum cpu usage per Container is 200m, but request is 100m.

The output shows that the Pod does not get created, because it defines an unacceptable container. 
That container is not acceptable because it specifies a CPU request that is lower than the enforced minimum.


⦿ Create a Pod that does not specify any CPU request or limit

[Create the Pod]
$ kubectl apply -f Pod_4.yaml --namespace=constraints-cpu-example
$ kubectl apply -f https://k8s.io/examples/admin/resource/cpu-constraints-pod-4.yaml --namespace=constraints-cpu-example

[View detailed information about the Pod]
$ kubectl get pod constraints-cpu-demo-4 --namespace=constraints-cpu-example --output=yaml
...
resources:
  limits:
    cpu: 800m
  requests:
    cpu: 800m

Because that container did not specify its own CPU request and limit, the control plane applied the default CPU request and limit from the LimitRange for this namespace.
At this point, your Pod may or may not be running. Recall that a prerequisite for this task is that your Nodes must have at least 1 CPU available for use.
If each of your Nodes has only 1 CPU, then there might not be enough allocatable CPU on any Node to accommodate a request of 800 millicpu.
If you happen to be using Nodes with 2 CPU, then you probably have enough CPU to accommodate the 800 millicpu request.

[Delete the Pod]
$ kubectl delete pod constraints-cpu-demo-4 --namespace=constraints-cpu-example

[Delete the Namespace]
$ kubectl delete namespace constraints-cpu-example
