我正在使用节点js创建代理服务器,并希望将来自一个Pod的请求代理到kubernetes的单节点集群中的其他Pod。这是我的节点js代码,、、、
const express = require("express");
const httpProxy = require("express-http-proxy");
const app = express();
const serviceone = httpProxy("serviceone:3000"); // I am using service names here but its not working
// Authentication
app.use((req, res, next) => {
// TODO: my authentication logic
console.log("Always.....");
next();
});
app.get("/", (req, res, next) => {
res.json({ message: "Api Gateway Working" });
});
// Proxy request
app.get("/:data/api", (req, res, next) => {
console.log("Request Recieved");
serviceone(req, res, next);
});
app.listen(5000, () => {
console.log("Api Gateway Running");
});
这些是我的services.yml文件
apiVersion: apps/v1
kind: Deployment
metadata:
name: serviceone
labels:
app: serviceone
spec:
replicas: 1
selector:
matchLabels:
app: serviceone
template:
metadata:
labels:
app: serviceone
spec:
containers:
- name: serviceone
image: swa/serviceone
ports:
- containerPort: 3000
---
apiVersion: v1
kind: Service
metadata:
name: serviceone
spec:
selector:
app: serviceone
ports:
- protocol: TCP
port: 3000
targetPort: 3000
nodePort: 31000
type: LoadBalancer
我应该在http代理中使用什么名称,以便它可以代理请求?
我尝试了serviceone:3000
,http://serviceone:3000
,http://localhost:3000
(不适用于不同的广告连播)。任何帮助将不胜感激
编辑-Node js apigateway pod
apiVersion: apps/v1
kind: Deployment
metadata:
name: apigateway
labels:
app: apigateway
spec:
replicas: 1
selector:
matchLabels:
app: apigateway
template:
metadata:
labels:
app: apigateway
spec:
containers:
- name: apigateway
image: swa/apigateway3
ports:
- containerPort: 5000
---
apiVersion: v1
kind: Service
metadata:
name: apigateway
spec:
selector:
app: apigateway
ports:
- protocol: TCP
port: 5000
targetPort: 5000
nodePort: 31005
type: LoadBalancer
在我的node js应用程序中,我将URL更改为
const serviceone = httpProxy('serviceone.default.svc.cluster.local:3000');
通过点击此链接https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#services 但仍然没有运气
我遇到了错误
错误:getaddrinfo EAI_AGAIN servicethree.sock-shop.svc.cluster.local 在GetAddrInfoReqWrap.onlookup上[按完成状态](dns.js:66:26)