개발강의정리/DevOps

[데브옵스를 위한 쿠버네티스 마스터] 애플리케이션 스케줄링과 라이프사이클 관리 - 멀티플 스케줄러

nineDeveloper 2021. 1. 19.
728x90

멀티플 스케줄러


멀티 스케줄러의 필요성

my-scheduler.yaml

apiVersion: v1
kind: ServiceAccount
metadata:
  name: my-scheduler
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: my-scheduler-as-kube-scheduler
subjects:
- kind: ServiceAccount
  name: my-scheduler
  namespace: kube-system
roleRef:
  kind: ClusterRole
  name: system:kube-scheduler
  apiGroup: rbac.authorization.k8s.io
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: my-scheduler-as-volume-scheduler
subjects:
- kind: ServiceAccount
  name: my-scheduler
  namespace: kube-system
roleRef:
  kind: ClusterRole
  name: system:volume-scheduler
  apiGroup: rbac.authorization.k8s.io
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    component: scheduler
    tier: control-plane
  name: my-scheduler
  namespace: kube-system
spec:
  selector:
    matchLabels:
      component: scheduler
      tier: control-plane
  replicas: 1
  template:
    metadata:
      labels:
        component: scheduler
        tier: control-plane
        version: second
    spec:
      serviceAccountName: my-scheduler
      containers:
      - command:
        - /usr/local/bin/kube-scheduler
        - --address=0.0.0.0
        - --leader-elect=false
        - --scheduler-name=my-scheduler
        image: gcr.io/my-gcp-project/my-kube-scheduler:1.0
        livenessProbe:
          httpGet:
            path: /healthz
            port: 10251
          initialDelaySeconds: 15
        name: kube-second-scheduler
        readinessProbe:
          httpGet:
            path: /healthz
            port: 10251
        resources:
          requests:
            cpu: '0.1'
        securityContext:
          privileged: false
        volumeMounts: []
      hostNetwork: false
      hostPID: false
      volumes: []

두 포드 스케줄링

  • 멀티 스케줄러를 사용해 두 포드를 스케줄
  • schedulerName 에 default-scheduler 를 작성하거나 아무 서술이 없는 경우 default- scheduler로 실행됨
  • 두 번째 포드는 my-scheduler를 사용

sched-pod.yaml

apiVersion: apps/v1
kind: Pod
metadata:
  name: annotation-default-scheduler
  labels:
    name: multischeduler-example
spec:
  schedulerName: default-scheduler
  containers:
  - name: pod-with-default-annotation-container
    image: k8s.gcr.io/pause:2.0
---
apiVersion: apps/v1
kind: Pod
metadata:
  name: annotation-second-scheduler
  labels:
    name: multischeduler-example
spec:
  schedulerName: my-scheduler
  containers:
  - name: pod-with-second-annotation-container
    image: k8s.gcr.io/pause:2.0

권한이 없는 두번째 Scheduler 는 Pending 상태가 됨

$ kubectl get pod | grep sche
annotation-default-scheduler   1/1     Running
annotation-second-scheduler    0/1     Pending

클러스터롤에 권한이 부재

  • 클러스터에 API 권한을 부여하면 my-scheduler도 활성화 가능
  • 다음 명령어로 클러스터 롤을 편집
$ kubectl edit clusterrole system:kube-scheduler
  • ResourceNames에 my-scheduler 추가

728x90

댓글

💲 추천 글