Manual Scheduling

  • Set node (modify nodeName will not work)

    1
    2
    3
    # Ex. Pod
    spec:
    nodeName: node01
  • Create a Binding object instead, add pass the binding to api in data parameter

Label Selector

1
kubectl get pods --selector app=my-app
  • Use annotations to store non-selector metadata

Taints and Tolerations

  • Taints mark nodes

    1
    2
    3
    4
    # add
    kubectl taint nodes node-name key=value:taint-effect
    # remove
    kubectl taint nodes node-name key=value:taint-effect-
  • taint-effect: NoSchedule, PreferNoSchedule, NoExecute

  • Tolerations mark pods

    1
    2
    3
    4
    5
    6
    7
    # Ex. Pod
    spec:
    tolerations:
    - key: key
    operator: Equal
    value: value
    effect: taint-effect

Node Selectors

  • Label nodes

    1
    kubectl label nodes node-name key=value
  • Configure node selector

    1
    2
    3
    4
    # Ex. Pod
    spec:
    nodeSelector:
    key: value

Node Affinity

1
2
3
4
5
6
7
8
9
10
# Ex. pod
spec:
affinity:
nodeAffinity:
<type>:
nodeSelectorTerms:
- matchExpressions:
- key: key
operator: In/NotIn/Exists/etc.
values: values
  • Types
    • requireDuringSchedulingIgnoreDuringExecution
    • preferredDuringSchedulingIgnoredDuringExecution
    • requiredDuringSchedulingRequiredDuringExecution

Resource Requirements and Limits

1
2
3
4
5
6
7
8
9
10
# Ex. Pod
spec:
containers:
resources:
requests:
memory: 256Mi
cpu: 0.5
limits:
memory: 512Mi
cpu: 1
  • Can create LimitRange object to overwrite default requests and limits
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    apiVersion: v1
    kind: LimitRange
    metadata:
    name: new-limit-range
    spec:
    limits:
    - default:
    memory: 1Gi
    cpu: 2
    defaultRequest:
    memory: 512Gi
    cpu: 1
    type: Container

Daemon Sets

  • Make sure that a specify pod always runs on each node
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    apiVersion: apps/v1
    kind: DaemonSet
    metadata:
    name: my-daemon-set
    spec:
    selector:
    matchLabels:
    app: my-daemon
    template:
    metadata:
    labels:
    app: my-daemon
    spec:
    containers:
    - name: daemon-name
    image: daemon-image

Static Pods

  • Without master node, worker node can also create pods based on pod definition in the manifest directory
  • manifest directory path can be configured in kubelet.service
    1
    2
    3
    4
    5
    ExecStart= ... \\
    --pod-manifest-path=/etc/Kubernetes/manifests \\
    # or
    --config=kubeconfig.yaml \\
    ...
1
2
# kubeconfig.yaml
staticPodPath: /etc/Kubernetes/manifests
  • Use docker ps command to confirm pods if there is not kube-api-server
  • Or use kubectl get pods to get both pods and static pods. But you cannot use kubectl to modify static pods

Multiple Schedulers

  • Set default scheduler

    1
    2
    3
    4
    # kube-scheduler.service
    ExecStart= ... \\
    --scheduler-name=custom-scheduler \\
    ...
  • Create a new scheduler

    1
    2
    3
    4
    5
    6
    7
    # Copy from kube-scheduler
    # add
    spec:
    containers:
    - command:
    - --scheduler-name=custom-scheduler
    - --lock-object-name=custom-scheduler
  • Use scheduler

    1
    2
    3
    4
    # Ex. Pod
    spec:
    containers:
    - schedulerName: customer-scheduler