K8s默认只有ready的pod才能被作为svc的后端,但有时希望即使pod没有准备就绪,服务发现机制也能够发现所有匹配服务标签选择器的pod
针对这个需求可以配置一个注释
service.alpha.kubernetes.io/tolerate-unready-endpoints:true
表示允许将未就绪的pod作为后端服务
Nacos的svc就需要这个配置
kind: Service
apiVersion: v1
metadata:
name: nacos-headless
namespace: nacos
labels:
app: nacos
annotations:
service.alpha.kubernetes.io/tolerate-unready-endpoints: 'true'
spec:
ports:
- name: server
protocol: TCP
port: 8848
targetPort: 8848
- name: client-rpc
protocol: TCP
port: 9848
targetPort: 9848
- name: raft-rpc
protocol: TCP
port: 9849
targetPort: 9849
- name: old-raft-rpc
protocol: TCP
port: 7848
targetPort: 7848
selector:
app: nacos
clusterIP: None
type: ClusterIP
sessionAffinity: None
但是今日部署新的集群发现会出现这个报错
2022/05/10 19:04:03 lookup nacos-headless on 192.168.0.10:53: no such host
2022/05/10 19:04:04 lookup nacos-headless on 192.168.0.10:53: no such host
2022/05/10 19:04:05 lookup nacos-headless on 192.168.0.10:53: no such host
2022/05/10 19:04:06 lookup nacos-headless on 192.168.0.10:53: no such host
2022/05/10 19:04:07 lookup nacos-headless on 192.168.0.10:53: no such host
2022/05/10 19:04:08 lookup nacos-headless on 192.168.0.10:53: no such host
2022/05/10 19:04:09 lookup nacos-headless on 192.168.0.10:53: no such host
2022/05/10 19:04:10 lookup nacos-headless on 192.168.0.10:53: no such host
2022/05/10 19:04:11 lookup nacos-headless on 192.168.0.10:53: no such host
2022/05/10 19:04:12 lookup nacos-headless on 192.168.0.10:53: no such host
2022/05/10 19:04:13 lookup nacos-headless on 192.168.0.10:53: no such host
2022/05/10 19:04:14 lookup nacos-headless on 192.168.0.10:53: no such host
看报错是无法解析svc的域名 但是这个域名又不太对 svc的域名不应该是这个呀::(怒)这个报错上网搜索也没有记录 一顿操作后看到新的集群是1.20版本的 忽然想到是不是有地方和新版本不适配呢
上网一搜还真找到 这个注释可能会在新版本被去掉
于是添加新的字段 publishNotReadyAddresses: true
再次启动果然启动成功了
NAME READY STATUS RESTARTS AGE
nacos-0 1/1 Running 0 5m31s
nacos-1 1/1 Running 0 4m9s
nacos-2 1/1 Running 0 2m10s
不禁感叹 真的是一个小配置 能让人忙活一下午:@(内伤)
记录下 看看是否有人会碰到这个问题