istio 给 pod 注入 sidecar 后,无法通过 pod_ip:grpc_port 直接调用 grpc

2023-02-09 19:20:57 +08:00
 meso5533
给 pod 注入 sidecar 后,无法通过 pod_ip:grpc_port 直接调用 grpc:

rpc error: code = Unavailable desc = error reading from server: EOF

只能通过 service_name:grpc_port 调用

http 协议的服务倒是没这个问题

这是怎么回事?
1390 次点击
所在节点    Kubernetes
14 条回复
coderxy
2023-02-09 19:37:35 +08:00
可能是协议识别问题,sidecar 需要根据 service name 的 grpc-这种开头去识别协议,你直接用 ip:port 这种方式,它可能无法识别吧
coderxy
2023-02-09 19:41:58 +08:00
@coderxy 说错了,不是 service name 的 grpc-开头,是端口映射的 grpc-
GopherDaily
2023-02-09 20:41:21 +08:00
istioctl proxy-config listener xxxx ;你 pod 和 svc 不是同一个 port ?
meso5533
2023-02-09 21:15:25 +08:00
@GopherDaily pod 和 svc 是相同的 port
istioctl proxy-config -n test-k8s listeners test-k8s-server-9cbcf8b9b-4s2q5 --port 16071
ADDRESS PORT MATCH DESTINATION
0.0.0.0 16071 Trans: raw_buffer; App: http/1.1,h2c Route: 16071
0.0.0.0 16071 ALL PassthroughCluster
awalkingman
2023-02-09 21:41:20 +08:00
要通过 podip 请求服务,那你得在另一个 pod 里去请求目标 podip ,所以你是在 pod A 里通过 podip 发起 grpc 请求到 pod B 吗
meso5533
2023-02-09 22:03:56 +08:00
@newskillsget 是的
luvroot
2023-02-09 23:17:08 +08:00
pod 之间 ip 互通需要 k8s 平台插件配置的支持。
luvroot
2023-02-09 23:19:03 +08:00
iptables 或则 tcpdump 抓包看一下哪里配置有问题大概率网络插件配置有问题
GopherDaily
2023-02-10 00:29:39 +08:00
@meso5533 https://istio.io/latest/docs/ops/diagnostic-tools/proxy-cmd/ 自己先走一遍吧,看 envoy 的 listener 包不包括 pod ip ,估计是不包括的;你走用了 mesh 了,为什么要走 pod ip ,走 svc ip 也会做负载均衡的
GopherDaily
2023-02-10 00:30:18 +08:00
或者用 headless
saltbo
2023-02-10 13:51:37 +08:00
awalkingman
2023-02-10 19:03:49 +08:00
@saltbo 受楼上启发,楼主把 pod 和 svc 的 yaml 文件发出来看看
meso5533
2023-02-10 23:17:59 +08:00
apiVersion: v1
kind: Service
metadata:
name: test-k8s-server-grpc
namespace: test-k8s
spec:
ports:
- name: grpc
port: 16071
protocol: TCP
targetPort: 16071
selector:
app: test-k8s-server

---

apiVersion: v1
kind: Service
metadata:
name: test-k8s-server-debug
namespace: test-k8s
annotations:
prometheus.io/scrape: 'true'
prometheus.io/port: '15225'
spec:
ports:
- name: debug
port: 15225
protocol: TCP
targetPort: 15225
selector:
app: test-k8s-server

---

apiVersion: apps/v1
kind: Deployment
metadata:
name: test-k8s-server
namespace: test-k8s
spec:
replicas: 1
selector:
matchLabels:
app: test-k8s-server
template:
metadata:
name: test-k8s-server
labels:
app: test-k8s-server
spec:
containers:
- name: test-k8s-server
image: xxxxxx:latest
command:
- /root/test_k8s
- server
- --log-level
- debug
ports:
- name: grpc
containerPort: 16071
- name: debug
containerPort: 15225
imagePullSecrets:
- name: regcred

grpc 的 port 无法正常通信,debug( http 协议)的 port 可以
meso5533
2023-02-10 23:19:38 +08:00
@meso5533 通过 service_name:grpc_port 的话可以正常通信,但是通过 pod_ip:grpc_port 不行

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/914685

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX