---
# System prepended metadata

title: '[k8s] Taints & Tolerations'
tags: [scheduling, kubernetes]

---

[k8s] Taints & Tolerations
============
###### tags: `kubernetes` `scheduling`
> 不保證有`tolerations`的pod一定會部署在被`taint`的node
> > 因為如果先遇到沒有任何`taint`時，會優先部署

# Add taints to Node
```sh=
kubectl taint nodes node-name key=value:taint-effect
```

## taint effect
+ what happend to PODs that DO NOT TOLERATE this taint?
+ types of taint-effect
    + NoSchedule | PreferNoSchedule | NoExecute
+ `NoSchedule`: no scheduled or evicted from existing nodes

```shell=
kubectl taint nodes node1 app=blue:NoSchedule
```

## remove taint on controlplane
```shell=
kubectl taint nodes controlplane node-role.kubernetes.io/control-plane:NoSchedule-
```

# Add toleration to PODs
```yaml=
# pod-definition.yaml
apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
spec:
  containers:
  - name: nginx-container
    image: nginx
  tolerations:
  - key: app
    operator: Equal
    value: blue 
    effect: NoSchedule
```

![](https://i.imgur.com/FurVRl3.jpg =400x)
