요청 <= 제한
제한 만 설정하는 경우 요청이 제한 양 만큼 설정됨
리소스 타입
단점: 실시간, cpu/memory 메트릭 수집
vi inventory/mycluster/group_vars/k8s-cluster/addons.yml
metrics_server_enabled: true
ansible-playbook -i inventory/mycluster/inventory.ini cluster.yml --become
minikube addons enable metrics-server
kubectl top nodes
kubectl top pods
kubectl describe node <NODE>
spec:
containers:
- resources:
requests:
cpu: X
memory: X
limits:
cpu: X
memory: X
제한 만 설정하는 경우 요청이 제한 양 만큼 설정됨
CPU 부하 테스트
kubectl exec -it <POD> -- sha1sum /dev/zero
apiVersion: v1
kind: LimitRange
metadata:
name: lim1
spec:
limits:
- type: Container
default: # 기본 limit
cpu: 10m
memory: 20M
defaultRequest: # 기본 request
cpu: 5m
memory: 10M
- type: Pod
max: # 할당 최대 값
cpu: 1000m
memory: 1G
#min: # 할당 최소 값
maxLimitRequestRatio:
cpu: 2
memory: 2
- type: PersistentVolumeClaim
min:
storage: 1Gi
max:
storage: 5Gi
default, defaultRequest는 Container 타입에만 선언
오브젝트의 개수의 제한
apiVersion: v1
kind: ResourceQuota
metadata:
name: rq
spec:
hard:
pods: 10
services: 5
services.loadbalancers: 1
services.nodeports: 2
configmaps: 5
secrets: 5
갯수 제한할 때 많이 씀
kubectl scale
kubelet(cAdvisor)
cAdvisor: Container Advisor
Pod -> cAdvisor(kubelet) -> Metrics Server -> HPA(scale out? in?)
원하는 레플리카 수 = ceil[현재 레플리카 수 * ( 현재 메트릭 값 / 원하는 메트릭 값 )]
metrics-server
실시간 메트릭 수집 처리
CPU, MEMORY 메트릭 수집
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: hpa
spec:
maxReplicas: 10
minReplicas: 1
scaleTargetRef:
apiVersion: apps/v1
kind: ReplicaSet
name: rs1
targetCPUUtilizationPercentage: 70
스케일 대상이 되는 컨트롤러는 반드시 요청(request)가 설정되어 있어야 함
온프레임에서는 hpa만 가능
pod의 개수만 조절 가능
스케일 대상이 되는 컨트롤러는 반드시 요청(request)이 있어야함.
cool-down timer/delay
apiVersion: v1
kind: Pod
metadata:
name: nnpod
spec:
nodeName: k8s-w3
containers:
- name: web
image: nginx
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: nnrs
spec:
replicas: 2
selector:
matchLabels:
app: nnrs
template:
metadata:
labels:
app: nnrs
spec:
nodeName: k8s-w3
containers:
- name: web
image: nginx
kubectl labels node k8s-w2 gpu=titan
kubectl labels node k8s-w3 gpu=titan
apiVersion: v1
kind: Pod
metadata:
name: nspod
spec:
nodeSelector:
gpu: titan
containers:
- name: web
image: nginx
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: nsrs
spec:
replicas: 2
selector:
matchLabels:
app: nsrs
template:
metadata:
labels:
app: nsrs
spec:
nodeSelector:
gpu: titan
containers:
- name: web
image: nginx
node에 레이블을 붙이고 그 노드와 매칭이 되는 파드를 배치하게 된다.
kubectl cordon|uncordon
kubectl drain
cordon: 해당 노드 스케줄링 금지
drain: 현재 실행되고 있는 파드 퇴거(Evict)
drain/cordon을 하는 경우, 반드시 uncordon
cordon은 새로운 스케쥴링을 금지한다.(기존의 것은 존재)
drain은 노드에 있는 pod를 퇴거시킨다.(옮기는 거 x)