V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
meso5533
V2EX  ›  Kubernetes

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

  •  
  •   meso5533 · 2023-02-09 19:20:57 +08:00 · 1370 次点击
    这是一个创建于 436 天前的主题,其中的信息可能已经有所发展或是发生改变。
    给 pod 注入 sidecar 后,无法通过 pod_ip:grpc_port 直接调用 grpc:

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

    只能通过 service_name:grpc_port 调用

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

    这是怎么回事?
    14 条回复    2023-02-10 23:19:38 +08:00
    coderxy
        1
    coderxy  
       2023-02-09 19:37:35 +08:00
    可能是协议识别问题,sidecar 需要根据 service name 的 grpc-这种开头去识别协议,你直接用 ip:port 这种方式,它可能无法识别吧
    coderxy
        2
    coderxy  
       2023-02-09 19:41:58 +08:00
    @coderxy 说错了,不是 service name 的 grpc-开头,是端口映射的 grpc-
    GopherDaily
        3
    GopherDaily  
       2023-02-09 20:41:21 +08:00
    istioctl proxy-config listener xxxx ;你 pod 和 svc 不是同一个 port ?
    meso5533
        4
    meso5533  
    OP
       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
        5
    awalkingman  
       2023-02-09 21:41:20 +08:00
    要通过 podip 请求服务,那你得在另一个 pod 里去请求目标 podip ,所以你是在 pod A 里通过 podip 发起 grpc 请求到 pod B 吗
    meso5533
        6
    meso5533  
    OP
       2023-02-09 22:03:56 +08:00
    @newskillsget 是的
    luvroot
        7
    luvroot  
       2023-02-09 23:17:08 +08:00
    pod 之间 ip 互通需要 k8s 平台插件配置的支持。
    luvroot
        8
    luvroot  
       2023-02-09 23:19:03 +08:00
    iptables 或则 tcpdump 抓包看一下哪里配置有问题大概率网络插件配置有问题
    GopherDaily
        9
    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
        10
    GopherDaily  
       2023-02-10 00:30:18 +08:00
    或者用 headless
    awalkingman
        12
    awalkingman  
       2023-02-10 19:03:49 +08:00
    @saltbo 受楼上启发,楼主把 pod 和 svc 的 yaml 文件发出来看看
    meso5533
        13
    meso5533  
    OP
       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
        14
    meso5533  
    OP
       2023-02-10 23:19:38 +08:00
    @meso5533 通过 service_name:grpc_port 的话可以正常通信,但是通过 pod_ip:grpc_port 不行
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2611 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 15:41 · PVG 23:41 · LAX 08:41 · JFK 11:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.