kubernetes 如何在AKS中为多个端点编写Ingress控制器

htrmnn0y  于 2023-08-03  发布在  Kubernetes
关注(0)|答案(2)|浏览(87)

我必须在AKS中为多个部署的服务编写Ingress控制器。
用例。
1.我已经创建了函数应用程序映像并将其部署在AKS集群中
1.现在,Individual服务有端点,我单独测试了它,它工作正常,并给出了响应。
问题:
我已经编写了入口控制器,并使用了rewrite-target以某种方式工作于单个API,但当我多次使用rewrite-target时,现有的一个不工作,只有最新的一个工作。
代码:

kind: Ingress
metadata:
  name: test-ingress
  namespace: containerpoc
  annotations:
     nginx.ingress.kubernetes.io/ssl-redirect: "false"
     nginx.ingress.kubernetes.io/use-regex: "true"
     nginx.ingress.kubernetes.io/rewrite-target: /api/AccountBalance?account
     #nginx.ingress.kubernetes.io/rewrite-target: /api/Refining?account
     #nginx.ingress.kubernetes.io/rewrite-target: /api/RefiningDetail?CustRefNum
     #nginx.ingress.kubernetes.io/rewrite-target: /api/Transactions?accounts
spec:
  ingressClassName: nginx
  rules:
  - http:
      paths:
      - path: /account
        pathType: Prefix
        backend:
          service:
            name: accountbalance-service
            port:
              number: 80
      - path: /account/balanceref
        pathType: Prefix
        backend:
          service:
            name: accountbalance-service
            port:
              number: 80 
      - path: /transaction
        pathType: Prefix
        backend:
          service:
            name: transactions-service
            port:
              number: 80 ```

The above code is working for a single API but I need to make it for multiple API/endpoints
The ask is how to set up the ingress which can support multiple API route-based URL

I am expecting the URL to look like

In browser

IP/Account?account=1
IP/Transaction?account=1
IP/refining?CustomRefnum=&&Ref=2323-oo&DateReceived=03-May-2023&account=0000

Thanks
Sudhir

字符串

vqlkdk9b

vqlkdk9b1#

您可以在不同的名称空间中为各自的service/url定义多个入口。或者为每个API端点创建具有不同名称的新入口对象。

kind: Ingress
metadata:
  name: test-ingress-refining
  namespace: containerpoc
  annotations:
     nginx.ingress.kubernetes.io/ssl-redirect: "false"
     nginx.ingress.kubernetes.io/use-regex: "true"
    #  nginx.ingress.kubernetes.io/rewrite-target: /api/AccountBalance?account
     nginx.ingress.kubernetes.io/rewrite-target: /api/Refining?account
     #nginx.ingress.kubernetes.io/rewrite-target: /api/RefiningDetail?CustRefNum
     #nginx.ingress.kubernetes.io/rewrite-target: /api/Transactions?accounts
spec:
  ingressClassName: nginx
  rules:
  - http:
      paths:
      - path: /account
        pathType: Prefix
        backend:
          service:
            name: accountbalance-service
            port:
              number: 80
      - path: /account/balanceref
        pathType: Prefix
        backend:
          service:
            name: accountbalance-service
            port:
              number: 80 
      - path: /transaction
        pathType: Prefix
        backend:
          service:
            name: transactions-service
            port:
              number: 80

字符串

knpiaxh1

knpiaxh12#

您可以在不同的名称空间中为各自的service/url定义多个入口。或者为每个API端点创建具有不同名称的新入口对象。

相关问题