阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

kubernetes endpoint一会消失一会出现的问题剖析

126次阅读
没有评论

共计 2541 个字符,预计需要花费 7 分钟才能阅读完成。

问题现象

发现某个 service 的后端 endpoint 一会显示有后端,一会显示没有。显示没有后端,意味着后端的 address 被判定为 notready。

endpoint 不正常的时候:

[root@localhost /]# kubectl get ep --namespace cxqt npth-price  -o yaml
apiVersion: v1
kind: Endpoints
metadata:
  ...
  uid: 9ed3abd1-8eff-11e7-b345-f8758831889c
subsets:
- notReadyAddresses:
  - ip: 10.1.3.70
    nodeName: 11.2.3.10
...

endpoint 正常的时候:

[root@localhost /]# kubectl get ep --namespace cxqt npth-price  -o yaml
apiVersion: v1
kind: Endpoints
metadata:
  ...
  uid: 9ed3abd1-8eff-11e7-b345-f8758831889c
subsets:
- addresses:
  - ip: 10.1.3.70
    nodeName: 11.2.3.10
...

问题分析

查看源码,可以看到 endpoint 是根据 pod 的 status 中的 conditions 中 type 是 Ready 的字典中的 status 是否为 True 进行判断。

// IsPodReady returns true if a pod is ready; false otherwise.
func IsPodReady(pod *Pod) bool {return IsPodReadyConditionTrue(pod.Status)
}

// IsPodReady retruns true if a pod is ready; false otherwise.
func IsPodReadyConditionTrue(status PodStatus) bool {condition := GetPodReadyCondition(status)
    return condition != nil && condition.Status == ConditionTrue
}
apiVersion: v1
kind: Pod
metadata:
    ...
    name: e9ebca20-0f3e-4974-8178-715cbbf5c627
status:
  conditions:
  - lastProbeTime: null
    lastTransitionTime: 2017-09-08T02:58:41Z
    status: "True"
    type: Initialized
  - lastProbeTime: null
    lastTransitionTime: 2017-09-08T02:59:11Z
    status: "False"
    type: Ready
  - lastProbeTime: null
    lastTransitionTime: 2017-09-08T02:58:41Z
    status: "True"
    type: PodScheduled
...

再进行日志查看,发现这个 status 字段是在由 kube-controller-manager 进行的更新为 False。

查看日志,发现 kube-controller-manager 更新的原因是因为 controller-manager 判断 node 上报心跳超时了。

I0919 16:05:35.383806   20248 nodecontroller.go:1007] node 11.2.3.10 hasn't been updated for 40.032883982s. Last ready condition is: {Type:Ready Status:True LastHeartbeatTime:2017-09-19 16:04:46 +0800 CST LastTransitionTime:2017-09-19 16:04:46 +0800 CST Reason:KubeletReady Message:kubelet is posting ready status}
...
I0919 16:05:35.387629   20248 controller_utils.go:320] Recording status change NodeNotReady event message for node 11.2.3.10
I0919 16:05:35.387679   20248 controller_utils.go:238] Update ready status of pods on node [11.2.3.10]

而反过来查看 11.2.3.10 节点上的 kubelet,上面因为有许多容器、镜像等。kubelet 在准备上报信息时,需要收集容器、镜像等的信息。虽然 kubelet 默认是 10 秒上报一次,但是实际的上报周期约为 20~50 秒。而 kube-controller-manager 判断 node 上报心跳超时的时间为 40 秒。所以会有一定概率超时。一旦超时,kube-controller 会将该 node 上的所有 pod 的 conditions 中 type 是 Ready 的字典中的 status 置为 False。

解决方案

目前一个较为简单的方案是在 kube-controller 上配置这个超时时间 node-monitor-grace-period 长一些。建议配置为 60~120s。

GitHub 为什么选择了 Kubernetes?http://www.linuxidc.com/Linux/2017-08/146362.htm

在 Kubernetes 集群中运行 WordPress  http://www.linuxidc.com/Linux/2017-09/146989.htm

kubeadm 搭建 Kubernetes 集群  http://www.linuxidc.com/Linux/2017-07/145505.htm

使用 kubeadm 在 Ubuntu 16.04 上搭建 Kubernetes1.5 集群  http://www.linuxidc.com/Linux/2017-07/145504.htm

本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-10/147491.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-21发表,共计2541字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中