简体   繁体   English

网关如何连接Kubernetes中的其他服务?

[英]How does gateway connect other services in Kubernetes?

I am attaching the image of my application flow.我附上了我的应用程序流程的图像。 Here the Gateway and other services are created using NestJS.这里的网关和其他服务是使用 NestJS 创建的。 The request for any API comes through the gateway.对任何 API 的请求都通过网关发出。

The Gateway-pod and API-pod communicate using TCP protocol . Gateway-pod 和 API-pod 使用 TCP 协议进行通信

After deployment the Gateway is not able to discover any API pods.部署后,网关无法发现任何 API pod。

I am attaching the YAML image file also for both Gateway & Pods .我还为Gateway 和 Pods附加了 YAML 图像文件。 Please do let me know what mistake I am doing in the YAML file.请让我知道我在 YAML 文件中犯了什么错误。

                    **APPLICATION DIAGRAM**

在此处输入图像描述

Gateway YAML网关 YAML

apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: roushan
  name: gateway-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: roushan-app
  template:
    metadata:
      labels:
        app: roushan-app
    spec:
      containers:
        - name: gateway-container
          image: nest-api-gateway:v8
          ports:
          - containerPort: 1000

apiVersion: v1
kind: Service
metadata:
  namespace: roushan
  name: gateway-svc
spec:
  selector:
    app: roushan-app
  ports:
    - name: gateway-svc-container
      protocol: TCP
      port: 80
      targetPort: 1000
  type: LoadBalancer

Pod YAML吊舱 YAML

apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: roushan
  name: pod1-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: roushan-app
  template:
    metadata:
      labels:
        app: roushan-app
    spec:
      containers:
        - name: pod1-container
          image: nest-api-pod1:v2
          ports:
          - containerPort: 4000

apiVersion: v1
kind: Service
metadata:
   namespace: roushan
   name: pod1-srv
spec:
  selector:
    app: roushan-app
  ports:
    - name: pod1-svc-container
      protocol: TCP
      port: 80
      targetPort: 4000

the gateway should be able to access the services by their DNS name.网关应该能够通过其 DNS 名称访问服务。 for example pod1-srv.svc.cluster.local, if this does not work you may need to look at the Kubernetes DNS setup.例如 pod1-srv.svc.cluster.local,如果这不起作用,您可能需要查看 Kubernetes DNS 设置。

I have not used AKS, they may use a different domain name for the cluster other than svc.cluster.local我没有使用过 AKS,他们可能会为集群使用不同的域名,而不是 svc.cluster.local

YAML Points YAML 积分

Ideally, you should be keeping the different selectors across the deployment .理想情况下,您应该在部署中保留不同的选择器

You are using the same selectors for both deployments.您对两个部署使用相同的选择器。 Gateway and application deployment.网关和应用程序部署。

Service will forward the traffic to deployment based on selectors and labels, this might redirect the service-2 request to POD-1 .服务将根据选择器和标签将流量转发到部署,这可能会将service-2请求重定向到POD-1

Networking联网

You gateway service(Pods) connect to internal service by just service-name like: pod1-srv if in same namespaces.您的网关服务(Pods)仅通过service-name连接到内部服务,例如: pod1-srv如果在相同的命名空间中。

if gateway and application in different namespaces you have to call each other like http://<servicename>.<namespace>.svc.cluster.local如果网关和应用程序位于不同的命名空间中,则必须互相调用,例如http://<servicename>.<namespace>.svc.cluster.local

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 apollo gateway (federation) 无法连接到 kubernetes 环境中的服务 - apollo gateway (federation) fails to connect to services in kubernetes environment API 网关,用于使用 Kubernetes 运行的服务? - API gateway for services running with Kubernetes? Azure 应用网关如何连接 kubernetes 入口 controller (nginx) - Azure application gateway how to connect with kubernetes ingress controller (nginx) Kubernetes 服务的快速网关配置 - Express-gateway config for Kubernetes services 如何通过Kubernetes运营商创建的服务连接应用程序? - How to connect applications with services created through Kubernetes operators? Kubernetes:如何在任意端口上将一个 Pod 连接到另一个 Pod - 有或没有服务? - Kubernetes: How to connect one pod to another on an arbitrary port - with or without services? 如何将本地Java服务连接到远程Kubernetes服务 - How to connect local java service to remote kubernetes services 如何让两个 Kubernetes 服务相互通信? - How to make two Kubernetes Services talk to each other? pod如何与群集外的其他服务/服务器通信? 通过其IP,或通过kubernetes处理的NAT IP - How does a pod communicate with other services/server outside of the cluster? via its IP, or via NAT IP handled by kubernetes 我的服务如何在 kubernetes 部署中相互通信? - How can my services communicate with each other in a kubernetes deployment?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM