[//]: # (Confidential document)
[//]: # (01/05/2025)
[//]: # (v 1.7.3)

# Kubernetes  labs v1.7.3 - Administration

## Quotas

A resource quota, defined by a ResourceQuota object, provides constraints that limit aggregate resource consumption per namespace. 
It can limit the quantity of objects that can be created in a namespace by type, as well as the total amount of compute resources that may be consumed by resources in that namespace.


## Lab1 : Quotas

 - Apply the Quota manifest
 - Get the list of Quotas
 - Describe Quota to get detailed information
 - Apply the Deployment manifest
 - Get the list of Pods
 - Get the list of Quotas
 - Describe Quota to get detailed information
 - Scale the Deployment to 4 replicas
 - Get the details of the scaled Deployment
 - Describe the ReplicaSet associated with the scaled Deployment
 
 
```
kubectl apply -f manifests/quotas.yaml
kubectl get quota
kubectl describe quota

kubectl apply -f manifests/deploy-quotas-example.yaml
kubectl get po
kubectl get quota
kubectl describe quota 
kubectl scale deploy deploy-quotas-example --replicas=4
kubectl get deploy deploy-quotas-example
kubectl describe  deploy deploy-quotas-example
kubectl describe rs 

kubectl delete -f manifests/

```

## Limit ranges


A LimitRange is a policy to constrain the resource allocations (limits and requests) that you can specify for each applicable object kind (such as Pod or PersistentVolumeClaim) in a namespace.

A LimitRange provides constraints that can:

 - Enforce minimum and maximum compute resources usage per Pod or Container in a namespace.
 - Enforce minimum and maximum storage request per PersistentVolumeClaim in a namespace.
 - Enforce a ratio between request and limit for a resource in a namespace.
 - Set default request/limit for compute resources in a namespace and automatically inject them to Containers at runtime.

A LimitRange is enforced in a particular namespace when there is a LimitRange object in that namespace.


## Lab 2 : Default Request & Default Limit 

 - Apply the LimitRange
 - Describe the LimitRange to verify it has been created
 - Apply a sample Pod
 - Get the details of the Pod, including CPU and memory resource requests and limits
 - Delete the LimitRange


```
kubectl apply -f manifests/container-limit-range-example1.yaml
kubectl describe limitrange/container-limit-range-example1
kubectl apply -f manifests/pod-example1.yaml
kubectl get pod pod-example1 --output=custom-columns=NAME:.metadata.name,CPU-R:.spec.containers[*].resources.requests.cpu,MEMORY-R:.spec.containers[*].resources.requests.memory,CPU-L:.spec.containers[*].resources.limits.cpu,MEMORY-L:.spec.containers[*].resources.limits.memory
kubectl delete limitrange/container-limit-range-example1
```

## Lab 3 : Min & Max  & Default Request & Default Limit

 - Apply the LimitRange
 - Describe the LimitRange to verify it has been created
 - Apply a sample Pod
 - Get the details of the Pod, including CPU and memory resource requests and limits
 - Delete the LimitRange


```
kubectl apply -f manifests/container-limit-range-example2.yaml
kubectl describe limitrange/container-limit-range-example2
kubectl apply -f manifests/pod-example2.yaml
kubectl get pod pod-example2 --output=custom-columns=NAME:.metadata.name,CPU-R:.spec.containers[*].resources.requests.cpu,MEMORY-R:.spec.containers[*].resources.requests.memory,CPU-L:.spec.containers[*].resources.limits.cpu,MEMORY-L:.spec.containers[*].resources.limits.memory
```

## Pod QOS

Kubernetes classifies the Pods that you run and allocates each Pod into a specific quality of service (QoS) class. 
Kubernetes uses that classification to influence how different pods are handled. Kubernetes does this classification based on the resource requests of the Containers in that Pod, along with how those requests relate to resource limits. 
This is known as Quality of Service (QoS) class. Kubernetes assigns every Pod a QoS class based on the resource requests and limits of its component Containers. QoS classes are used by Kubernetes to decide which Pods to evict from a Node experiencing Node Pressure. The possible QoS classes are Guaranteed, Burstable, and BestEffort. When a Node runs out of resources, Kubernetes will first evict BestEffort Pods running on that Node, followed by Burstable and finally Guaranteed Pods. When this eviction is due to resource pressure, only Pods exceeding resource requests are candidates for eviction.


## Lab 4 : QoS classes Guaranteed, Burstable, and BestEffort

 - Apply the Pod manifest
 - Get the QoS class of the Pod
 - Describe the Pod to get detailed information
 
```
kubectl apply -f manifests/pod-qos-example.yaml
kubectl get pod pod-qos-example --output=jsonpath='{.status.qosClass}'
kubectl describe po pod-qos-example
```

## Clean up

```
kubectl delete -f manifests/

```
