티스토리 뷰

DevOps

[CKA] Scheduling

신잼 2022. 3. 4. 14:44

◼ Schedule manually

nodeName

nodeName is the simplest form of node selection constraint, but due to its limitations it is typically not used
  • podSpec의 field
  • scheduler는 어떤 노드에 pod를 배치해야 할지 결정이 나면 nodeName이름을 붙인다.
  • scheduler가 없다면 직접 nodeName에 node이름을 적어서 배치시킬 수 있다.
    github.com/kodekloudhub/certified-kubernetes-administrator-course/tree/master/docs
  • 이미 배포한 pod를 직접 스케줄링하려면 Binding 리소스를 만들고 직접 api 요청을 해야 한다.
    github.com/kodekloudhub/certified-kubernetes-administrator-course/tree/master/docs
  • limitions
    • nodeName에 해당하는 node가 없다면 pod는 실행되지 않고 경우에 따라 삭제될 수도 있다.
    • node의 자원이 충분하지 않으면 pod가 배치되지 않는다.
    • cloud 환경에서의 node 이름은 항상 예상 가능하거나 안정적이지 않다.

nodeSelector

nodeSelector is the simplest recommended form of node selection constraint
  • podSpec의 field
  • key, value로 match 되는 node label를 찾아 배치한다.
  • limitation
    • 하나의 key, value만 지정할 수 있다. (or, and 등 복잡한 조건 불가능)
  • node에 label이 있어야 한다.
    • kubectl label nodes <node-name =

github.com/kodekloudhub/certified-kubernetes-administrator-course/tree/master/docs

◼ Taints & Tolerence

Taints and tolerations work together to ensure that pods are not scheduled onto inappropriate nodes.
  • 보안과는 관련이 없고 스케줄 하는데 제약사항에 불가하다
  • 특정 node가 특정 pod만 배치되도록 보장하는 것이지 모든 특정 pod가 특정 node로 배치되게 하는 것은 아니다.
    • 특정 pod가 특정 node로만 배치 되게 하는 방법은 node affinity를 사용한다.
  • Master node에는 pod가 스케줄 되지 않는데 taint가 있기 때문이다.
    github.com/kodekloudhub/certified-kubernetes-administrator-course/tree/master/docs

Taints::node에 설정

github.com/kodekloudhub/certified-kubernetes-administrator-course/tree/master/docs

  • node-name: 지정할 node 이름
  • key: taint key 이름
  • value: taint value 이름
  • taint-effect: pod에 toleration이 없을 때 취할 action
    • NoSchedule: 더 이상 절대 node에 배치시키지 않겠다는 설정
    • PreferNoSchedule: 더 이상 되도록 node에 배치 시키지 않겠다는 설정
    • NoExecute: NoSchedule에 더해서 이미 node에 존재하는 pod도 제거하는 설정
  • tanint 제거할 때는 마지막에 -를 붙인다.
    • kubectl taint nodes node1 key1=vlue:NoSchedule-

Toleration::pod에 설정

  • taint에 설정한 key, value, effect가 같아야 한다.
  • kubectl taint node1 app=blue:NoScedule 와 같다면 pod spec은 아래와 같다.
    github.com/kodekloudhub/certified-kubernetes-administrator-course/tree/master/docs
  • operator: default 값은 Equal이고 Exists를 사용하면 value는 생략 가능하다.

◼ Node Affinity

it allows you to constrain which nodes your pod is eligible to be scheduled on, based on labels on the node.
apiVersion: v1
kind: Pod
metadata:
  name: with-node-affinity
spec:
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: kubernetes.io/e2e-az-name
            operator: In
            values:
            - e2e-az1
            - e2e-az2
      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 1
        preference:
          matchExpressions:
          - key: another-node-label-key
            operator: In
            values:
            - another-node-label-value
  containers:
  - name: with-node-affinity
    image: k8s.gcr.io/pause:2.0
  • 유연하고(soft), 선호(preference)한 규칙을 통해 규칙을 만족하지 못하더라도 pod가 스케줄링될 수 있다.
  • operator를 사용해서 다양한 label 조건으로 스케줄링할 수 있다.
    • In, NotIn, Exists, DoesNotExist, Gt, Lt
    • DoesNotExist와 NotIn을 같이 사용하면 Anti-Affinity와 같은 효과를 본다.
  • 사용 가능한 Type으로는 2가지, 예정인 Type으로 1가지가 있다.
    Type DuringScheduling DuringExecution  
    requiredDuringSchedulingIgnoredDuringExecution Required Ignored available
    preferredDuringSchedulingIgnoredDuringExecution Preferred Ignored available
    preferredDuringSchedulingRequiredDuringExecution Required Required Planned
    • 스케줄링 단계에서 꼭 지켜져야 하면 required, 최대한 지켜져야 하면 preferred
    • 이미 존재하는 pod에 대해 evict를 하려면 Required 그냥 놔두려면 Ignored

◼ Resource requests & limits

  • container가 사용하는 자원을 알고 있다면 필요한 지원을 명시해줄 수 있다.
  • scheduler는 명시된 자원을 보고 적절한 node에 배치시킨다.
  • limit이 명시되어 있다면 강제적으로 리소스 사용량을 제한한다.
    apiVersion: v1
    kind: Pod
    metadata:
    name: frontend
    spec:
    containers:
    - name: app
    image: images.my-company.example/app:v4
    resources:
      requests:
        memory: "64Mi"
        cpu: "250m"
      limits:
        memory: "128Mi"
        cpu: "500m"
    - name: log-aggregator
    image: images.my-company.example/log-aggregator:v6
    resources:
      requests:
        memory: "64Mi"
        cpu: "250m"
      limits:
        memory: "128Mi"
        cpu: "500m"

cpu와 memory limit 차이점

cpu는 throtle이 되면서 limit을 넘지 않지만 memory는 limit을 넘을 수도 있다. 넘게 되면 terminate 된다.

github.com/kodekloudhub/certified-kubernetes-administrator-course/tree/master/docs

기본 limit 설정

LimitRange 리소스를 사용해서 기본 limit을 설정해줄 수 있다.

apiVersion: v1
kind: LimitRange
metadata:
  name: mem-limit-range
spec:
  limits:
  - default:
      memory: 512Mi
    defaultRequest:
      memory: 256Mi
    type: Container

◼ DaemonSet

A DaemonSet ensures that all (or some) Nodes run a copy of a Pod

github.com/kodekloudhub/certified-kubernetes-administrator-course/tree/master/docs

  • node가 cluster에서 제거되면
    • daemonset는 garbage collected
    • daemonset이 만든 pod와 함께 제거된다.
  • Usage
    • cluster storage, logs, mornitoring등에 사용된다.
    • kube-proxy나 weave 같은 addon도 daemonset이다.
  • scheduling 방식
    • default로 nodeName을 붙여서 스케줄링
    • NodeAffinity를 사용하는 ScheduleDaemonSetPods으로 스케줄 가능

◼ Static Pod

Static Pod are managed directly by the kubelet daemon on a specific node, without the API server observing them
  • kube API 가 아닌 kubelet이 직접 관리하는 pod
  • pod-manifest-path 옵션에 지정한 경로에 있는 mamifest를 자동으로 apply 한다.
    • --pod-maifest-path=/etc/kubernetes/manifests
  • pod-manifest-path로 직접 경로 지정 말고 config파일을 만들어 명시해줄 수 있다.
    • --config=kubeconfig.yaml
    • echo "staticPath: /etc/kubernetes/manifests" >> kubeconfig.yaml
      github.com/kodekloudhub/certified-kubernetes-administrator-course/tree/master/docs
  • kube api에 mirror pod를 생성한다.
    • static pod는 이름 끝에 node 이름이 붙는다. i.e. static-web-node01
    • static pod를 확인만 할 수 있고 지우려면 직접 manifest 파일을 지워줘야 한다.

◼ multi scheduler

github.com/kodekloudhub/certified-kubernetes-administrator-course/tree/master/docs

  • HA를 위해 multi node를 운영하며 여러 개의 scheduler를 만들 수 있다.
  • pod에 어떤 스케줄러를 사용할지 명시해줄 수 있다.
  • leader elect를 설정해주고 이름을 설정하기 위해 leader-elect, scheduler-name, lock-object-name을 설정해준다.
    • 현재 lock-object-name은 deprecated 됐고 leader-elect-resource-name을 사용해야 한다

Reference

반응형

'DevOps' 카테고리의 다른 글

[CKA] Cluster Maintenance  (0) 2022.03.08
[CKA] Application Lifecycle Management  (0) 2022.03.07
[CKA] logging & monitoring  (0) 2022.03.05
[CKA] Core Concepts  (0) 2022.03.02
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함