从另一个pod Kubernetes访问服务



我的k8s中运行着两个服务。
我试图从我的用户服务访问我的钱包服务,但我的curl cmd只返回504网关超时。

这里是我的入口

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: dev-ingress
namespace: dev
annotations:
nginx.ingress.kubernetes.io/ssl-redirect: "false"
# nginx.ingress.kubernetes.io/use-regex: "true"
# nginx.ingress.kubernetes.io/rewrite-target: /api/v1$uri
spec:
ingressClassName: nginx
rules:
- http:
paths:
- path: /api/v1/wallet
pathType: Prefix
backend:
service:
name: wallet-service
port:
number: 80
- path: /api/v1/user
pathType: Prefix
backend:
service:
name: accounts-service
port:
number: 80

这是我在帐户服务中传递env的方式。

http://wallet-service:3007

,当到达我的端点

时,我记录URLcurl http://EXTERNAL_IP/api/v1/user/health/wallet

所有其他不相关的端点工作

感谢您的帮助

我正在运行Azure Kubernetes

我的k8s中运行着两个服务。

  1. 您有实际的K8S服务吗?

    apiVerison: ...
    kind: Service
    
    • 检查kubectl get svc -A,你应该看到你的服务在那里
  2. 检查您的pod是否暴露于服务

    kubectl get endpoints -A
    
  3. 您是否在云提供商(GCP, Azure, AWS等)上运行,如果是,请检查您的安全配置(Azure的NSG, AWS的安全策略等)

  4. 检查内部沟通:

    # Log into one of the pods 
    kubectl exec -n <namespace> <pod name> sh
    # Try to connect to the other service with the FQDN
    curl -sv <servicename>.<namespace>.svc.cluster.local
    

更新:

  • 您评论说您正在Azure上运行,请检查NSG下打开的所需端口。
  • 假设你正在运行AKS,你需要找到MS_xxxx资源,你的NSG组将位于这个资源组下,编辑它并打开所需的端口

您正在尝试连接到http://wallet-service:3007/api/v1/wallet/health -您从哪里获得3007端口?

最新更新