kubelet对容器healthCheck的重定向是否应该follow?

下午,收到一条异常事件的告警,Reason:ProbWarning,什么意思呢?

想到刚给新版本的k8s(1.14)添加了事件监控,没一会便收到上述告警,之前版本(1.9)从没遇到过,而且服务一直正常,pod也没重启过,也没有Unhealthy的事件,为啥还会有Warning呢?

手动访问应用的healthCheck接口,发现跳转到了cas服务,url从serviceA.xx.xx变成了cas.xx.xx/serviceA.xx.xx,跨域名了,是由它引起的吗?

原因

查到一个k8s1.14的changelog里面提到了生成ProbWarning这个reason,原文:

kubelet
The deprecated --experimental-fail-swap-on flag has been removed (#69552, @Pingan2017)
Health check (liveness & readiness) probes using an HTTPGetAction will no longer follow redirects to different hostnames from the original probe request. Instead, these non-local redirects will be treated as a Success (the documented behavior). In this case an event with reason "ProbeWarning" will be generated, indicating that the redirect was ignored. If you were previously relying on the redirect to run health checks against different endpoints, you will need to perform the healthcheck logic outside the Kubelet, for instance by proxying the external endpoint rather than redirecting to it. (#75416, @tallclair)
原理

顺着找到了对应的PR 以及它对应的issue,它是说kubelet在做healthCheck的时候,执行了HTTP跳转,并将跳转后的结果作为凭据,不符合文档描述:

Any code greater than or equal to 200 and less than 400 indicates success. Any other code indicates failure.

理解为检查是不包含redirect的,即便跳转,也是同主机不同路径的跳转是可以被接收的,跨主机的跳转不被大家认同,但go的httplib默认则是follow了跳转,因此要调整为:
只follow本地同域名的重定向,而对有跨域跳转,则不follow,并直接认为是健康的(不再跟踪是否真正健康),并记录一条警告事件,也就是这里的ProbWarning

源码
禁跨域重定向

具体实现是构建client的时候,单独声明了CheckRedirect,以不做跳转和死循环处理。

client := &http.Client{
   
		CheckRedirect: redirectChecker(false),
	}

func redirectChecker(followNonLocalRedirect
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值