Manual Scheduling
Set node (modify nodeName will not work)
1
2
3# Ex. Pod
spec:
nodeName: node01Create 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 | # Ex. pod |
- Types
- requireDuringSchedulingIgnoreDuringExecution
- preferredDuringSchedulingIgnoredDuringExecution
- requiredDuringSchedulingRequiredDuringExecution
Resource Requirements and Limits
1 | # Ex. Pod |
- Can create
LimitRange
object to overwrite default requests and limits1
2
3
4
5
6
7
8
9
10
11
12
13apiVersion: 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
16apiVersion: 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
5ExecStart= ... \\
--pod-manifest-path=/etc/Kubernetes/manifests \\
# or
--config=kubeconfig.yaml \\
...
1 | # kubeconfig.yaml |
- 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-schedulerUse scheduler
1
2
3
4# Ex. Pod
spec:
containers:
- schedulerName: customer-scheduler