Kubernetes 알아보기 - 여러 스케줄러 만들기

안녕!

대부분의 대형 기술 회사는 소프트웨어에 대한 훌륭한 문서를 제공합니다. 특히 Kubernetes 설명서를 본 적이 있습니까? 그들은 아주 굉장합니다.

특히, 나는 어떤 주제에 대해 꽤 많이 주어진 예를 좋아합니다. Kubernetes 개념을 이해하기 위해 맹목적으로 따라갈 수 있습니다.

오늘은 쿠버네티스 클러스터에서 여러 스케줄러를 구성하는 방법은 물론 그들의 documentation에서 알아보기로 했습니다. 또한 Minikube 클러스터를 사용하고 싶었습니다. Minikubehere 설치 방법을 알아보세요.

Minikube 클러스터를 시작합니다.


%minikube start --driver=hyperkit
😄  minikube v1.25.2 on Darwin 12.4
✨  Using the hyperkit driver based on user configuration
👍  Starting control plane node minikube in cluster minikube
🔥  Creating hyperkit VM (CPUs=2, Memory=8192MB, Disk=20000MB) ...
🐳  Preparing Kubernetes v1.23.3 on Docker 20.10.12 ...
    ▪ kubelet.housekeeping-interval=5m
    ▪ Generating certificates and keys ...
    ▪ Booting up control plane ...
    ▪ Configuring RBAC rules ...
🔎  Verifying Kubernetes components...
    ▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🌟  Enabled addons: default-storageclass, storage-provisioner
🏄  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default

Minikube 클러스터에서 실행 중인 kube-scheduler 포드에서 사용하는 이미지를 찾습니다.


%kubectl get pod kube-scheduler-minikube -o yaml -n kube-system | grep image
    image: k8s.gcr.io/kube-scheduler:v1.23.3
    imagePullPolicy: IfNotPresent
    image: k8s.gcr.io/kube-scheduler:v1.23.3
    imageID: docker-pullable://k8s.gcr.io/kube-scheduler@sha256:32308abe86f7415611ca86ee79dd0a73e74ebecb2f9e3eb85fc3a8e62f03d0e7

필요한 모든 리소스에 대한 YAML 파일 생성



다음은 다른 스케줄러를 생성하는 데 필요한 모든 리소스를 생성하는 Kubernetes 설명서에 제공된 YAML file 입니다. 두 번째 스케줄러도 위와 같은 이미지를 사용할 예정이니 꼭 이것을 사용하자. 이것이 의미하는 바는 문서에 언급된 이미지를 위의 이미지로 대체하는 것입니다.
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: v1
kind: ConfigMap
metadata:
  name: my-scheduler-config
  namespace: kube-system
data:
  my-scheduler-config.yaml: |
    apiVersion: kubescheduler.config.k8s.io/v1beta2
    kind: KubeSchedulerConfiguration
    profiles:
      - schedulerName: my-scheduler
    leaderElection:
      leaderElect: false    
---
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
        - --config=/etc/kubernetes/my-scheduler/my-scheduler-config.yaml
        image: k8s.gcr.io/kube-scheduler:v1.23.3
        livenessProbe:
          httpGet:
            path: /healthz
            port: 10259
            scheme: HTTPS
          initialDelaySeconds: 15
        name: kube-second-scheduler
        readinessProbe:
          httpGet:
            path: /healthz
            port: 10259
            scheme: HTTPS
        resources:
          requests:
            cpu: '0.1'
        securityContext:
          privileged: false
        volumeMounts:
          - name: config-volume
            mountPath: /etc/kubernetes/my-scheduler
      hostNetwork: false
      hostPID: false
      volumes:
        - name: config-volume
          configMap:
            name: my-scheduler-config

필요한 모든 객체 생성


%kubectl apply -f my-scheduler.yaml
serviceaccount/my-scheduler created
clusterrolebinding.rbac.authorization.k8s.io/my-scheduler-as-kube-scheduler created
clusterrolebinding.rbac.authorization.k8s.io/my-scheduler-as-volume-scheduler created
configmap/my-scheduler-config created
deployment.apps/my-scheduler created

새 스케줄러가 생성되었는지 확인


%kubectl get deployment -n kube-system
NAME           READY   UP-TO-DATE   AVAILABLE   AGE
coredns        1/1     1            1           23h
my-scheduler   1/1     1            1           8s

%kubectl get pods -n kube-system
NAME                               READY   STATUS    RESTARTS   AGE
coredns-64897985d-4vstq            1/1     Running   0          23h
etcd-minikube                      1/1     Running   0          23h
kube-apiserver-minikube            1/1     Running   0          23h
kube-controller-manager-minikube   1/1     Running   0          23h
kube-proxy-w4srd                   1/1     Running   0          23h
kube-scheduler-minikube            1/1     Running   0          23h
my-scheduler-5546b885fb-mdgcn      1/1     Running   0          18s
storage-provisioner                1/1     Running   0          23h

포드를 생성하되 이번에는 새 스케줄러를 사용하도록 합니다.


%cat pod-using-second-scheduler.yaml
apiVersion: 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

%kubectl apply -f pod-using-second-scheduler.yaml
pod/annotation-second-scheduler created

%kubectl get event
LAST SEEN   TYPE      REASON      OBJECT                            MESSAGE
19s         Normal    Scheduled   pod/annotation-second-scheduler   Successfully assigned default/annotation-second-scheduler to minikube
18s         Normal    Pulling     pod/annotation-second-scheduler   Pulling image "k8s.gcr.io/pause:2.0"
17s         Normal    Pulled      pod/annotation-second-scheduler   Successfully pulled image "k8s.gcr.io/pause:2.0" in 1.25784015s
17s         Normal    Created     pod/annotation-second-scheduler   Created container pod-with-second-annotation-container
17s         Normal    Started     pod/annotation-second-scheduler   Started container pod-with-second-annotation-container

그게 다야. 짜잔!

좋은 웹페이지 즐겨찾기