Resource Quotas & Limits in Kubernetes
Делаю: 09.04.2019
По материалам из видео индуса:
https://www.youtube.com/watch?v=4C-0idGOi2A&list=PL34sAs7_26wNBRWM6BDhnonoA5FMERax0&index=17
Подготовили кластер и окружение как здесь.
Resource Quotas
$ kubectl create namespace quota-demo-ns
$ kubectl create -f https://bitbucket.org/sysadm-ru/kubernetes/raw/faf2f86a2c1bb82053c5aba9ea7c96463e4e61b0/yamls/7-quota-count.yaml
$ kubectl -n quota-demo-ns describe quota quota-demo1
Name: quota-demo1
Namespace: quota-demo-ns
Resource Used Hard
-------- ---- ----
configmaps 0 1
pods 0 2
$ kubectl -n quota-demo-ns create configmap cm1 --from-literal=name=venkatn
$ kubectl -n quota-demo-ns describe quota quota-demo1
Name: quota-demo1
Namespace: quota-demo-ns
Resource Used Hard
-------- ---- ----
configmaps 1 1
pods 0 2
// Ошибка!!!
$ kubectl -n quota-demo-ns create configmap cm2 --from-literal=name=venkatn
$ kubectl -n quota-demo-ns delete cm cm1
$ kubectl -n quota-demo-ns run nginx --image=nginx --replicas=1
$ kubectl -n quota-demo-ns describe quota quota-demo1
Name: quota-demo1
Namespace: quota-demo-ns
Resource Used Hard
-------- ---- ----
configmaps 0 1
pods 1 2
$ kubectl -n quota-demo-ns scale deploy nginx --replicas=3
$ kubectl -n quota-demo-ns get all
NAME READY STATUS RESTARTS AGE
pod/nginx-7db9fccd9b-g7vgr 1/1 Running 0 2m50s
pod/nginx-7db9fccd9b-ttzfd 1/1 Running 0 60s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/nginx 2/3 2 2 2m50s
NAME DESIRED CURRENT READY AGE
replicaset.apps/nginx-7db9fccd9b 3 2 2 2m50s
$ kubectl -n quota-demo-ns delete deploy nginx
$ kubectl -n quota-demo-ns delete quota quota-demo1
Resource Limits (CPU, Memory etc.)
$ kubectl create -f https://bitbucket.org/sysadm-ru/kubernetes/raw/faf2f86a2c1bb82053c5aba9ea7c96463e4e61b0/yamls/7-quota-mem.yaml
$ kubectl -n quota-demo-ns describe quota quota-demo-mem
Name: quota-demo-mem
Namespace: quota-demo-ns
Resource Used Hard
-------- ---- ----
limits.memory 0 500Mi
// Ошибка должны быть определены лимиты памяти
$ kubectl create -f https://bitbucket.org/sysadm-ru/kubernetes/raw/faf2f86a2c1bb82053c5aba9ea7c96463e4e61b0/yamls/7-pod-quota-mem.yaml
$ cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: nginx
namespace: quota-demo-ns
spec:
containers:
- image: nginx
name: nginx
resources:
limits:
memory: "100Mi"
EOF
$ kubectl -n quota-demo-ns describe quota quota-demo-mem
Name: quota-demo-mem
Namespace: quota-demo-ns
Resource Used Hard
-------- ---- ----
limits.memory 100Mi 500Mi
$ kubectl delete -f https://bitbucket.org/sysadm-ru/kubernetes/raw/faf2f86a2c1bb82053c5aba9ea7c96463e4e61b0/yamls/7-pod-quota-mem.yaml
$ kubectl -n quota-demo-ns delete quota quota-demo-mem
Limit range
$ kubectl create -f https://bitbucket.org/sysadm-ru/kubernetes/raw/faf2f86a2c1bb82053c5aba9ea7c96463e4e61b0/yamls/7-quota-limitrange.yaml
$ kubectl -n quota-demo-ns describe limitrange mem-limitrange
Name: mem-limitrange
Namespace: quota-demo-ns
Type Resource Min Max Default Request Default Limit Max Limit/Request Ratio
---- -------- --- --- --------------- ------------- -----------------------
Container memory - - 50Mi 300Mi -
$ kubectl create -f https://bitbucket.org/sysadm-ru/kubernetes/raw/faf2f86a2c1bb82053c5aba9ea7c96463e4e61b0/yamls/7-pod-quota-mem.yaml
$ kubectl delete -f https://bitbucket.org/sysadm-ru/kubernetes/raw/faf2f86a2c1bb82053c5aba9ea7c96463e4e61b0/yamls/7-pod-quota-mem.yaml
$ kubectl create -f https://bitbucket.org/sysadm-ru/kubernetes/raw/faf2f86a2c1bb82053c5aba9ea7c96463e4e61b0/yamls/7-quota-limitrange.yaml
$ cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ResourceQuota
metadata:
name: quota-demo-mem
namespace: quota-demo-ns
spec:
hard:
limits.memory: "500Mi"
requests.memory: "100Mi"
EOF
Добавили строку: requests.memory: “100Mi”
$ kubectl -n quota-demo-ns describe quota quota-demo-mem
Name: quota-demo-mem
Namespace: quota-demo-ns
Resource Used Hard
-------- ---- ----
limits.memory 0 500Mi
requests.memory 0 100Mi
$ cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: nginx
namespace: quota-demo-ns
spec:
containers:
- image: nginx
name: nginx
resources:
limits:
memory: "200Mi"
EOF
Ошибка, тк просит больше 100.
$ cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: nginx
namespace: quota-demo-ns
spec:
containers:
- image: nginx
name: nginx
resources:
limits:
memory: "200Mi"
requests:
memory: "50Mi"
EOF