drain 驱逐流程:先在 Node 节点删除 pod,然后再在其他 Node 节点创建该 pod。所以为了确保 drain 驱逐 pod 过程中不中断服务(即做到”无感知”地平滑驱逐),必须保证要驱逐的 pod 副本数大于 1,并且采用了”反亲和策略”将这些 pod 调度到不同的 Node 节点上了!也就是说,在”多个 pod 副本+反亲和策略”的场景下,drain 驱逐过程对容器服务是没有影响的。
知识点(k8s 污点和容忍度)
污点(Taints):定义在节点上,用于拒绝 Pod 调度到此节点,除非该 Pod 具有该节点上的污点容忍度。被标记有 Taints 的节点并不是故障节点。
容忍度(Tolerations):定义在 Pod 上,用于配置 Pod 可容忍的节点污点,K8S 调度器只能将 Pod 调度到该 Pod 能够容忍的污点的节点上。
污点和容忍度(Toleration)相互配合,可以用来避免 Pod 被分配到不合适的节点上。 每个节点上都可以应用一个或多个污点,这表示对于那些不能容忍这些污点的 Pod, 是不会被该节点接受的。
排斥等级
NoSchedule:没有配置此污点容忍度的新 Pod 不能调度到此节点,节点上现存的 Pod 不受影响。
PreferNoSchedule:没有配置此污点容忍度的新 Pod 尽量不要调度到此节点,如果找不到合适的节点,依然会调度到此节点。
NoExecute:没有配置此污点容忍度的新 Pod 对象不能调度到此节点,节点上现存的 Pod 会被驱逐。
容忍度操作符
Equal:容忍度与污点必须在 key、value 和 effect 三者完全匹配。
Exists:容忍度与污点必须在 key 和 effect 二者完全匹配,容忍度中的 value 字段要使用空值。
k8s 时间同步集群故障
重启 kube-system 命名空间下的服务 然后重启对应服务
kubeadm 加入 master 节点失败
报错: error execution phase check-etcd: etcd cluster is not healthy: context deadli
原因分析:
由于该节点已经存在所以无法加入
起因:
master2 挂掉了,其他节点无法连接该节点
尝试通过移除节点,并重新引导节点加入集群的方式去解决
master1 执行
1 2 3 4 5 6 7 8 9
kubectl delete node master2 # master1 上执行的
### master2上执行 kubeadm reset --cri-socket=unix:///var/run/cri-dockerd.sock kubeadm join 192.168.1.101:6443 --token n258e9.63nk1rcbcu6422c4 --discovery-token-ca-cert-hash sha256:4916a116d04b8ac46228bae887445bbe087cac4e8096fc489fe2fc6a6060708e --control-plane --certificate-key b5e26ce8cdfa2d92412766d4cd22be7a56283a7ab3c35fca902db37c777dc0ad --cri-socket=unix:///var/run/cri-dockerd.sock # -->: # [check-etcd] Checking that the etcd cluster is healthy # error execution phase check-etcd: etcd cluster is not healthy: failed to dial endpoint https://192.168.3.102:2379 with maintenance client: context deadline exceeded # To see the stack trace of this error execute with --v=5 or higher
# 看到如下警告事件, 起始就是无法获取到当前资源使用情况 # unable to get metrics for resource cpu: unable to fetch metrics from resource metrics API: the server could not find the requested resource (get pods.metrics.k8s.io)