记一次K8S健康检查失败

Posted by 张伟真 on 2023-08-25
Estimated Reading Time 3 Minutes
Words 700 In Total
Viewed Times

一次K8S健康检查失败

一、背景

1
流水线部署成功,POD一直无法Running,循环重启。使用kubectl descibe pod 查看pod事件为健康检查失败

二、临时解决方案

1
确认服务无问题,临时取消健康检查

三、分析过程

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
查看健康检查配置为: 
livenessProbe:
initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
successThreshold: {{ .Values.livenessProbe.successThreshold }}
failureThreshold: {{ .Values.livenessProbe.failureThreshold }}
exec:
command:
- /bin/sh
- -c
- >
nc -z localhost {{ .Values.service.port }}
readinessProbe:
initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
successThreshold: {{ .Values.readinessProbe.successThreshold }}
failureThreshold: {{ .Values.readinessProbe.failureThreshold }}
exec:
command:
- /bin/sh
- -c
- >
nc -z localhost {{ .Values.service.port }}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
查看valus里相关配置内容为:
livenessProbe:
initialDelaySeconds: 60
periodSeconds: 30
timeoutSeconds: 3
successThreshold: 1
failureThreshold: 3

readinessProbe:
initialDelaySeconds: 30
periodSeconds: 15
timeoutSeconds: 3
successThreshold: 1
failureThreshold: 3
service:
enabled: true
port: 80
type: ClusterIP
name: frontend
1
2
健康检查的命令为: nc -z localhost 80
从容器中查看pod监听的端口为3000,如下图

图片

1
修改valus的端口配置后健康检查依然失败,再次仔细排查问题为上图中pod监听的地址为pod IP,所以nc -z localhost 3000 不通
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
查看dockerfile找到相关配置为:
EXPOSE 3000
CMD if [ -n "$PROXY_URL" ]; then \
export HOSTNAME="127.0.0.1"; \
protocol=$(echo $PROXY_URL | cut -d: -f1); \
host=$(echo $PROXY_URL | cut -d/ -f3 | cut -d: -f1); \
port=$(echo $PROXY_URL | cut -d: -f3); \
conf=/etc/proxychains.conf; \
echo "strict_chain" > $conf; \
echo "proxy_dns" >> $conf; \
echo "remote_dns_subnet 224" >> $conf; \
echo "tcp_read_time_out 15000" >> $conf; \
echo "tcp_connect_time_out 8000" >> $conf; \
echo "localnet 127.0.0.0/255.0.0.0" >> $conf; \
echo "localnet ::1/128" >> $conf; \
echo "[ProxyList]" >> $conf; \
echo "$protocol $host $port" >> $conf; \
cat /etc/proxychains.conf; \
proxychains -f $conf node server.js; \
else \
node server.js; \
fi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
排查到CMD配置中关键部分 export HOSTNAME="127.0.0.1"; 注明了监听地址为127.0.0.1=localhost,但实际监听地址为pod IP,所以并未进入这个then,而else里并没有相关配置,所以在else里注明export HOSTNAME="0.0.0.0";,修改后配置如下
CMD if [ -n "$PROXY_URL" ]; then \
export HOSTNAME="127.0.0.1"; \
protocol=$(echo $PROXY_URL | cut -d: -f1); \
host=$(echo $PROXY_URL | cut -d/ -f3 | cut -d: -f1); \
port=$(echo $PROXY_URL | cut -d: -f3); \
conf=/etc/proxychains.conf; \
echo "strict_chain" > $conf; \
echo "proxy_dns" >> $conf; \
echo "remote_dns_subnet 224" >> $conf; \
echo "tcp_read_time_out 15000" >> $conf; \
echo "tcp_connect_time_out 8000" >> $conf; \
echo "localnet 127.0.0.0/255.0.0.0" >> $conf; \
echo "localnet ::1/128" >> $conf; \
echo "[ProxyList]" >> $conf; \
echo "$protocol $host $port" >> $conf; \
cat /etc/proxychains.conf; \
proxychains -f $conf node server.js; \
else \
export HOSTNAME="0.0.0.0"; \
node server.js; \
fi

重新部署流水线后,POD成功Running,查看POD日志监听地址已生效

如果您喜欢此博客或发现它对您有用,则欢迎对此发表评论。 也欢迎您共享此博客,以便更多人可以参与。 如果博客中使用的图像侵犯了您的版权,请与作者联系以将其删除。 谢谢 !