[Kubernetes] CKA 시험 준비 - Scheduler

bluewhale·2021년 11월 1일
0

kubernetes

목록 보기
8/11
post-thumbnail

Scheduler

Assigning Pod to a node

nodeSelector: assgin a pod to a node via kube-scheduler

apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
  - image: nginx
    name: nginx
  nodeSelector:
    kubernetes.io/hostname: target-node

nodeName: manually assgin pod to node by kubelet, skipping kube-scheduler

apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
  - image: nginx
    name: nginx    
  nodeName: target-node

Select resources by label

$ kubectl get pods --selector="environment=prod"
$ kubectl get all -l="environment=prod,tier=backend"

Taints & Toleration

Create a taint & remove a taint

$ kubectl taint nodes production-node env=prod:NoSchedule
$ kubectl taint nodes production-node env=prod:NoSchedule- # -

Create a pod which tolerates the taint

# backend-prod.yaml
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: backend-prod
  name: backend-prod
spec:
  containers:
  - image: busybox
    name: backend-prod
    resources: {}
  tolerations:
  - key: env
    value: prod
    operator: Equal
    effect: NoSchedule
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}

Node Affinity

Add a label to node

$ kubectl label nodes <your-node-name> disktype=ssd

Create a deployment which has an node affinity rule

apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  affinity:
    nodeAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 1
        preference:
          matchExpressions:
          - key: disktype
            operator: In
            values:
            - ssd          
  containers:
  - name: nginx
    image: nginx

Resoure requests and limits

Control CPU and memory usage per container

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"

Static Pod

Static Pod의 yaml 파일 위치는 kubelet 실행 시 설정 값(kubelet --config=/var/lib/kubelet/config.yaml)에서 확인할 수 있다. 기본 값은 /etc/kubernetes/manifes이다.

profile
안녕하세요

0개의 댓글