问题描述
我无法从本地计算机连接到在远程 Kubernetes 集群中运行的 Stan 服务器。
nats ClusterIP None <none> 4222/TCP,6222/TCP,8222/TCP,7777/TCP,7422/TCP,7522/TCP
stan ClusterIP None <none> 7777/TCP
我运行 2 个端口转发命令:
kubectl port-forward -n nats svc/nats 4222:4222
kubectl port-forward -n nats svc/stan 7777:7777
这是我的代码:
nc,err := nats.Connect("nats://localhost:4222",nats.Name(clusterID))
if err != nil {
panic(fmt.Sprintf("Could not connect to nats,error: %s\n",err))
}
sc,err := stan.Connect(clusterID,clientID,stan.NatsConn(nc),stan.NatsURL(nc.ConnectedUrl()))
if err != nil {
panic(fmt.Sprintf("Could not connect to stan with clusterID \"%s\" and clientID: \"%s\" here is error: %s\n",clusterID,err))
}
我收到以下错误:
panic: Could not connect to stan with clusterID "stan" and clientID: "foo" here is error: stan: connect request timeout (possibly wrong cluster ID?)
集群 ID 正确。当我在集群中作为 pod 运行相同的代码(当然 nats URL 不同)时,一切正常。但出于开发目的,我需要从本地连接到 stan 服务器。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)