【问题标题】:How can i expose my EKS microservices via nginx ingress controller如何通过 nginx 入口控制器公开我的 EKS 微服务
【发布时间】:2021-08-20 12:17:12
【问题描述】:

我正在尝试通过 nginx 入口控制器将微服务与我的前端应用程序一起使用。

kubectl 应用 -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.48.1/deploy/static/provider/aws/deploy.yaml 以上是我们部署 nginx-controller 所遵循的命令。

参考 - https://kubernetes.github.io/ingress-nginx/deploy/#aws

-----我的集成A​​PI的deployment.yaml和service.yaml如下-------

'''

apiVersion: apps/v1
kind: Deployment
metadata:
  name: integrations-api
  labels:
    app: integrations-api
spec:
  replicas: 1
  selector:
    matchLabels:
      app: integrations-api
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: integrations-api
    spec:
      containers:
      - image: "###imagepath####"
        imagePullPolicy: Always
        name: integrations-api
        ports:
        - containerPort: 8083
          protocol: TCP

---

apiVersion: v1
kind: Service
metadata:
  name: integrations-api
  annotations:
    service.beta.kubernetes.io/aws-load-balancer-backend-protocol: "tcp,http"
    service.beta.kubernetes.io/aws-load-balancer-ssl-cert:  "###certpath###"
    service.beta.kubernetes.io/aws-load-balancer-ssl-ports: "https"
spec:
  type: LoadBalancer
  selector:
    app: integrations-api
  ports:
  - name: http
    port: 80
    targetPort: 8083
    protocol: TCP
  - name: https
    port: 443
    targetPort: 8083
    protocol: TCP

'''

------我的 ingress.yaml 看起来像这样--------

'''

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: example-ingress
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/force-ssl-redirect: "false"
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:  
  rules:  
  - http:
      paths:
          - path: /
            backend:
              serviceName: integrations-api
              servicePort: 80
          - path: /
            backend:
              serviceName: user-api
              servicePort: 80

'''

在我的节点 js 集成 API 代码中,我们添加了测试 API 路径,如下所示 '''

app.get('/camps', (req, res) => {
  let obj = {}
  res.send(obj);
});

'''

当我访问 nginx-controller 的端点时(这里是负载均衡器端点)https://####NLB-endpoint###/camps 我正在收到回复。

像 deployment.yaml、service.yaml 和 nodejs 代码一样的配置是为用户服务 api 编写的。但我没有得到用户 api 的响应 https://####NLB-endpoint###/users

注意,当我像下面这样改组入口文件时,我得到 https://####NLB-endpoint###/users 的响应,但不是 https://####NLB-endpoint# ##/营地。看起来 inress 正在走上仅在首位提及的道路。

'''

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: example-ingress
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/force-ssl-redirect: "false"
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
          - path: /
            backend:
              serviceName: user-api
              servicePort: 80
          - path: /
            backend:
              serviceName: integrations-api
              servicePort: 80
   

'''

任何线索我该如何解决这个问题? 提前致谢。如果有人指导我们,对您有很大帮助。

【问题讨论】:

    标签: kubernetes-ingress amazon-eks nginx-ingress


    【解决方案1】:

    此响应可能为时已晚。您正在尝试使用多个微服务创建基于路径的路由。在这种情况下,您需要设置路径。对于 user-api,您需要将 /user 设置为路径,然后对于 integrations-api,您需要指定另一个路径,例如 /camps。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-21
      • 2018-07-23
      • 2021-01-28
      • 2023-03-15
      • 2021-09-03
      • 2021-09-21
      • 2021-05-12
      • 1970-01-01
      相关资源
      最近更新 更多