PDB(PodDisruptionBudget)是为了自主中断时(除了节点crash)保障应用的高可用。
在使用 PDB 时,你需要弄清楚你的应用类型以及你想要的应对措施:
kubectl cordon snode name>
kubectl drain <node name>
cat nginx-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
k apply -f nginx-deployment.yaml
cat pdb.yaml
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: nginx-deployment
spec:
minAvailable: 1
selector:
matchLabels:
app: nginx
k apply -f pdb.yaml
cat ~/.kube/config
echo 'xxx' | base64 -d > admin.crt
echo 'xxx' | base64 -d > admin.key
cat eviction.json
{
"apiVersion": "policy/v1",
"kind": "Eviction",
"metadata": {
"name": "nginx-deployment-75f4d489b4-b6grv",
"namespace": "default"
}
}
curl -v -H 'Content-type: application/json' --key admin.key --cert admin.crt https://192.168.0.6:6443/api/v1/namespaces/default/pods/nginx-deployment-75f4d489b4-b6grv/eviction -d @eviction.json -k
k edit pdb
ALLOWED DISRUPTIONS为0代表一个都不能驱逐。
如果你将pdb中的minAvailable设置为0,那么这个节点就不能操作下线等操作了。