CKA (Certified Kubernetes Administrator)/Kode Kloud

02. Scheduling - Multiple Schedulers

seulseul 2022. 1. 20. 14:35

LABS – CERTIFIED KUBERNETES ADMINISTRATOR WITH PRACTICE TESTS > SCHEDULING   Multiple Schedulers

Scheduling

 

01. What is the name of the POD that deploys the default kubernetes scheduler in this environment?

 

정답 : kube-scheduler-controlplane

root@controlplane:~# kubectl get pod --all-namespaces
NAMESPACE     NAME                                   READY   STATUS    RESTARTS   AGE
kube-system   coredns-74ff55c5b-bsgrt                1/1     Running   0          8m50s
kube-system   coredns-74ff55c5b-m88xq                1/1     Running   0          8m50s
kube-system   etcd-controlplane                      1/1     Running   0          9m
kube-system   kube-apiserver-controlplane            1/1     Running   0          9m
kube-system   kube-controller-manager-controlplane   1/1     Running   0          9m
kube-system   kube-flannel-ds-5vdws                  1/1     Running   0          8m50s
kube-system   kube-proxy-bc7gw                       1/1     Running   0          8m50s
kube-system   kube-scheduler-controlplane            1/1     Running   0          9m

 

02. What is the image used to deploy the kubernetes scheduler?

Inspect the kubernetes scheduler pod and identify the image

 ask : k8s.gcr.io/kube-scheduler:v1.20.0

root@controlplane:~# kubectl describe pod kube-scheduler-controlplane -n kube-system
Name:                 kube-scheduler-controlplane
Namespace:            kube-system
Priority:             2000001000
Priority Class Name:  system-node-critical
Node:                 controlplane/10.9.208.6
Start Time:           Thu, 20 Jan 2022 05:48:02 +0000
Labels:               component=kube-scheduler
                      tier=control-plane
Annotations:          kubernetes.io/config.hash: 81d2d21449d64d5e6d5e9069a7ca99ed
                      kubernetes.io/config.mirror: 81d2d21449d64d5e6d5e9069a7ca99ed
                      kubernetes.io/config.seen: 2022-01-20T05:48:00.547032625Z
                      kubernetes.io/config.source: file
Status:               Running
IP:                   10.9.208.6
IPs:
  IP:           10.9.208.6
Controlled By:  Node/controlplane
Containers:
  kube-scheduler:
    Container ID:  docker://3ebe57943973e59f14acb16e3357474ab9944e1943f61c6b1de945c5cc0b79a5
    Image:         k8s.gcr.io/kube-scheduler:v1.20.0
    Image ID:      docker-pullable://k8s.gcr.io/kube-scheduler@sha256:beaa710325047fa9c867eff4ab9af38d9c2acec05ac5b416c708c304f76bdbef
    Port:          <none>
    Host Port:     <none>
    Command:
      kube-scheduler
      --authentication-kubeconfig=/etc/kubernetes/scheduler.conf
      --authorization-kubeconfig=/etc/kubernetes/scheduler.conf
      --bind-address=127.0.0.1
      --kubeconfig=/etc/kubernetes/scheduler.conf
      --leader-elect=true
      --port=0
    State:          Running
      Started:      Thu, 20 Jan 2022 05:47:44 +0000
    Ready:          True
    Restart Count:  0
    Requests:
      cpu:        100m
    Liveness:     http-get https://127.0.0.1:10259/healthz delay=10s timeout=15s period=10s #success=1 #failure=8
    Startup:      http-get https://127.0.0.1:10259/healthz delay=10s timeout=15s period=10s #success=1 #failure=24
    Environment:  <none>
    Mounts:
      /etc/kubernetes/scheduler.conf from kubeconfig (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  kubeconfig:
    Type:          HostPath (bare host directory volume)
    Path:          /etc/kubernetes/scheduler.conf
    HostPathType:  FileOrCreate
QoS Class:         Burstable
Node-Selectors:    <none>
Tolerations:       :NoExecute op=Exists
Events:            <none>

03. Deploy an additional scheduler to the cluster following the given specification.

Use the manifest file used by kubeadm tool. Use a different port than the one used by the current one.

  • Namespace: kube-system
  • Name: my-scheduler
  • Status: Running
  • Custom Scheduler Name
# Hint

Use the file at /etc/kubernetes/manifests/kube-scheduler.yaml 
to create your own scheduler.
# 정답

Copy kube-scheduler.yaml from the directory /etc/kubernetes/manifests/ 

to any other location and then change the name to my-scheduler.

Add or update the following command arguments in the YAML file:

- --leader-elect=false
- --port=10282
- --scheduler-name=my-scheduler
- --secure-port=0

Here, we are setting leader-elect to false 
for our new custom scheduler called my-scheduler.

We are also making use of a different port 10282 which is not currently
in use in the controlplane.

The default scheduler uses secure-port on port 10259 to serve HTTPS 
with authentication and authorization. 

This is not needed for our custom scheduler, 
so we can disable HTTPS by setting the value of secure-port to 0.


Finally, because we have set secure-port to 0, 
replace HTTPS with HTTP and use the correct ports under liveness and startup probes.

The final YAML file would look something like this:

---
apiVersion: v1
kind: Pod
metadata:
  labels:
    component: my-scheduler
    tier: control-plane
  name: my-scheduler
  namespace: kube-system
spec:
  containers:
  - command:
    - kube-scheduler
    - --authentication-kubeconfig=/etc/kubernetes/scheduler.conf
    - --authorization-kubeconfig=/etc/kubernetes/scheduler.conf
    - --bind-address=127.0.0.1
    - --kubeconfig=/etc/kubernetes/scheduler.conf
    - --leader-elect=false
    - --port=10282
    - --scheduler-name=my-scheduler
    - --secure-port=0
    image: k8s.gcr.io/kube-scheduler:v1.19.0
    imagePullPolicy: IfNotPresent
    livenessProbe:
      failureThreshold: 8
      httpGet:
        host: 127.0.0.1
        path: /healthz
        port: 10282
        scheme: HTTP
      initialDelaySeconds: 10
      periodSeconds: 10
      timeoutSeconds: 15
    name: kube-scheduler
    resources:
      requests:
        cpu: 100m
    startupProbe:
      failureThreshold: 24
      httpGet:
        host: 127.0.0.1
        path: /healthz
        port: 10282
        scheme: HTTP
      initialDelaySeconds: 10
      periodSeconds: 10
      timeoutSeconds: 15
    volumeMounts:
    - mountPath: /etc/kubernetes/scheduler.conf
      name: kubeconfig
      readOnly: true
  hostNetwork: true
  priorityClassName: system-node-critical
  volumes:
  - hostPath:
      path: /etc/kubernetes/scheduler.conf
      type: FileOrCreate
    name: kubeconfig
status: {}

Run 
kubectl create -f my-scheduler.yaml
and wait sometime for the container to be in running state.
# 나의 오답...

apiVersion: v1
kind: Pod
metadata:
  labels:
    component: my-scheduler
    tier: control-plane
  name: my-scheduler
  namespace: kube-system
spec:
  containers:
  - command:
    - my-scheduler
    - --authentication-kubeconfig=/etc/kubernetes/scheduler.conf
    - --authorization-kubeconfig=/etc/kubernetes/scheduler.conf
    - --bind-address=127.0.0.1
    - --kubeconfig=/etc/kubernetes/scheduler.conf
    - --leader-elect=true
    - --port=0
    image: k8s.gcr.io/my-scheduler:v1.20.0
    imagePullPolicy: IfNotPresent
    livenessProbe:
      failureThreshold: 8
      httpGet:
        host: 127.0.0.1
        path: /healthz
        port: 10259
        scheme: HTTPS
      initialDelaySeconds: 10
      periodSeconds: 10
      timeoutSeconds: 15
    name: my-scheduler
    resources:
      requests:
        cpu: 100m
    startupProbe:
      failureThreshold: 24
      httpGet:
        host: 127.0.0.1
        path: /healthz
        port: 10259
        scheme: HTTPS
      initialDelaySeconds: 10
      periodSeconds: 10
      timeoutSeconds: 15
    volumeMounts:
    - mountPath: /etc/kubernetes/scheduler.conf
      name: kubeconfig
      readOnly: true
  hostNetwork: true
  priorityClassName: system-node-critical
  volumes:
  - hostPath:
      path: /etc/kubernetes/scheduler.conf
      type: FileOrCreate
    name: kubeconfig

04. A POD definition file is given. Use it to create a POD with the new custom scheduler.

File is located at /root/nginx-pod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
  - image: nginx
    name: nginx
# 아래 한줄 추가
  schedulerName: my-scheduler

 

 

 

 


Bookmark

https://kubernetes.io/docs/tasks/extend-kubernetes/configure-multiple-schedulers/

 

Configure Multiple Schedulers

Kubernetes ships with a default scheduler that is described here. If the default scheduler does not suit your needs you can implement your own scheduler. Moreover, you can even run multiple schedulers simultaneously alongside the default scheduler and inst

kubernetes.io