[英]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.