线上搭的gpt服务502了,查询了nginx-ingress的容器日志,提示

2024/05/22 06:50:35 [error] 20624#20624: *8205050 connect() failed (111: Connection refused) while connecting to upstream, client: 180.98.131.151, server: chatgpt-test.chenm.xyz, request: "GET / HTTP/2.0", upstream: "http://10.95.248.77:3000/", host: "chatgpt-test.chenm.xyz"

然后查看了pod,情况,ip对,一切正常

# kubectl describe pod/chatgptweb-test-6d49fdf94f-2f7fx -n chatgpt
Name:             chatgptweb-test-6d49fdf94f-2f7fx
Namespace:        chatgpt
Priority:         0
Service Account:  default
Node:             cloud-cm/172.29.225.216
Start Time:       Sat, 18 May 2024 16:55:04 +0800
Labels:           app=chatgptweb-test-app
                  pod-template-hash=6d49fdf94f
Annotations:      cni.projectcalico.org/containerID: 81d4382e758a230d264050a86e4eab4c14fbc3188ead8bddb66a7c1416fa2911
                  cni.projectcalico.org/podIP: 10.95.248.77/32
                  cni.projectcalico.org/podIPs: 10.95.248.77/32
Status:           Running
IP:               10.95.248.77
IPs:
  IP:           10.95.248.77
Controlled By:  ReplicaSet/chatgptweb-test-6d49fdf94f
Containers:
  chatgptweb-test-app:
    Container ID:   containerd://dae5d6af551d086a780166a7ac7f87115c5959325824ca8fc0a23180ffef177b
    Image:          yidadaa/chatgpt-next-web:latest
    Image ID:       docker.io/yidadaa/chatgpt-next-web@sha256:bc3985634fef511fa2d81ef5af45e5dbb97a4f4dffd76547575b6b49961bd918
    Port:           3000/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Sat, 18 May 2024 16:55:07 +0800
    Ready:          True

直接集群中curl服务确实访问有问题

# curl http://10.95.248.77:3000
curl: (7) Failed to connect to 10.95.248.77 port 3000: Connection refused

但是post forward 给pod建立连接就可以了

# kubectl port-forward pod/chatgptweb-test-6d49fdf94f-2f7fx 8080:3000 -n chatgpt 
Forwarding from 127.0.0.1:8080 -> 3000
Forwarding from [::1]:8080 -> 3000

打印对应容器日志发现

strict_chain
proxy_dns
remote_dns_subnet 224
tcp_read_time_out 15000
tcp_connect_time_out 8000
localnet 127.0.0.0/255.0.0.0
localnet ::1/128
[ProxyList]
http 172.29.225.216 1081
[proxychains] config file found: /etc/proxychains.conf
[proxychains] preloading /usr/lib/libproxychains4.so
[proxychains] DLL init: proxychains-ng 4.16
   ▲ Next.js 14.1.1
   - Local:        http://127.0.0.1:3000
   - Network:      http://127.0.0.1:3000

 ✓ Ready in 97ms

找到问题了,监听了127.0.0.1,由此可见port-forward的机制和直接访问还是有区别的
查看了dockerfile,不知道为何加了代理,hostname就强制写127.0.0.1了

 if [ -n "$PROXY_URL" ]; then \
    export HOSTNAME="127.0.0.1"; \

还好这块内容在cmd里面,直接在yaml文件里面重写cmd把这行去掉就行了,解决!