Today I Learn - 50

이정빈·2021년 5월 10일
0

클라우드 엔지니어

목록 보기
52/53

Resource Management

  • 요청(request)
  • 제한(limit)

요청 <= 제한

제한 만 설정하는 경우 요청이 제한 양 만큼 설정됨

리소스 타입

  • cpu
  • memory
  • huge page

metrics-server

단점: 실시간, cpu/memory 메트릭 수집

kubespray
vi inventory/mycluster/group_vars/k8s-cluster/addons.yml

metrics_server_enabled: true
ansible-playbook -i inventory/mycluster/inventory.ini cluster.yml  --become
minikube
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

LimitRange

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 타입에만 선언

Resource Quota

오브젝트의 개수의 제한

apiVersion: v1
kind: ResourceQuota
metadata:
  name: rq
spec:
  hard:
    pods: 10
    services: 5
    services.loadbalancers: 1
    services.nodeports: 2
    configmaps: 5
    secrets: 5

갯수 제한할 때 많이 씀


Auto Scaling

  • Manual Scaling
kubectl scale
  • HPA
    • Horizontal Pod Autoscaler
    • scale out / in
    • 파드의 수를 조정
  • VPA
    • Vertical Pod Autoscaler
    • scale up / down
    • 파드 요청/제한 조정
  • CA
    • Cluster Autoscaler
    • Work Node scale out / in

HPA(Horizontal Pod Autoscaler)

  • ReplicaSet/ReplicationController
  • StatefulSet
  • Deployment

kubelet(cAdvisor)

cAdvisor: Container Advisor

Pod -> cAdvisor(kubelet) -> Metrics Server -> HPA(scale out? in?)

원하는 레플리카 수 = ceil[현재 레플리카 수 * ( 현재 메트릭 값 / 원하는 메트릭 값 )]
  • 원하는(desired) 메트릭 값
  • 현재(current) 메트릭 값
  • autoscaling/v1: CPU 메트릭
  • autoscaling/v2beta2: CPU, Memory, Custom 메트릭

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

  • scale in/down: 300s
    • 축소는 5분 유예기간

Scheduler

nodename

  • .spec.nodeName
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

nodeselector

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에 레이블을 붙이고 그 노드와 매칭이 되는 파드를 배치하게 된다.

cordon/drain

kubectl cordon|uncordon
kubectl drain
  • cordon: 해당 노드 스케줄링 금지

    • 노드 제거
    • 노드 유지보수
  • drain: 현재 실행되고 있는 파드 퇴거(Evict)

    • drain을 하면 자동 cordon이 됨
    • --ignore-daemonsets
    • --delete-local-data

drain/cordon을 하는 경우, 반드시 uncordon

cordon은 새로운 스케쥴링을 금지한다.(기존의 것은 존재)

drain은 노드에 있는 pod를 퇴거시킨다.(옮기는 거 x)

profile
WAS Engineer, Cloud Engineer(지망)

0개의 댓글