创建指向两个服务的 Kubernetes 入口

Creating a Kubernetes ingress pointing two services

要求:想要使用 HTTPS 入口部署 Minio 和另一个后端服务(不用于生产目的)

我一直在尝试创建一个入口以从 GKE 中的 Kubernetes 集群外部访问两个服务。这些是我尝试过的。

尝试一次

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: lightning-ingress
  namespace: default
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
  rules:
  - http:
      paths:
        - path: /storage
          backend:
            serviceName: minio
            servicePort: 9000
        - path: /portal
          backend:
            serviceName: oscar
            servicePort: 8080

尝试二

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: oscar
  annotations:
    # nginx.ingress.kubernetes.io/rewrite-target: /
    kubernetes.io/ingress.class: nginx
spec:
  rules:
  - http:
      paths:
      - backend:
          serviceName: oscar
          servicePort: 8080
  - host: storage.lightningfaas.tech
    http:
      paths:
      - backend:
          serviceName: minio
          servicePort: 9000

尝试三

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: lightning-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
  - http:
      paths:
      - backend:
          serviceName: minio
          servicePort: 9000
        path: /minio(/|$)(.*)
      - backend:
          serviceName: oscar
          servicePort: 8080
        path: /portal(/|$)(.*)

尝试四次

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: minio-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
  - host: minio.lightningfaas.tech
    http:
      paths:
      - backend:
          serviceName: minio
          servicePort: 9000
  - host: portal.lightningfaas.tech
    http:
      paths:
      - backend:
          serviceName: oscar
          servicePort: 8080

然而,上述 none 的尝试符合我的要求。它要么给出 404 0r 要么给出 503。但我可以确认为每个服务创建一个单独的入口工作正常,如下所示。

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: oscar
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
  - http:
      paths:
      - backend:
          serviceName: oscar
          servicePort: 8080
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: minio-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
  - http:
      paths:
      - backend:
          serviceName: minio
          servicePort: 9000

更改域服务器也需要花费大量时间进行测试,因此创建主机非常烦人,因为我必须等待大量时间来测试我的代码。还有什么我可以尝试的吗?

像下面这样的东西是理想的:

https://34.452.234.45:9000 > 将访问 minio

https://34.452.234.45:8080 > 将访问 oscar

您的建议和意见对我很有帮助。

Minio 掌舵图:https://github.com/minio/charts

Minio 部署

helm install --namespace oscar minio minio/minio --set accessKey=minio --set secretKey=password --set persistence.existingClaim=lightnig --set resources.requests.memory=256Mi 

奥斯卡掌舵人排行榜:https://github.com/grycap/helm-charts/tree/master/oscar

奥斯卡部署

helm install --namespace=oscar oscar oscar --set authPass=password --set service.type=ClusterIP --set createIngress=false --set volume.storageClassName=nfs --set minIO.endpoint=http://104.197.173.174 --set minIO.TLSVerify=false --set minIO.accessKey=minio --set minIO.secretKey=password --set serverlessBackend=openfaas

根据 kubernetes 文档,简单的扇出示例应该可以解决您的问题。 下面给出了一个简单的扇出示例,其中同一主机有两个不同的路径用于两个不同的服务。

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: simple-fanout-example
spec:
  rules:
  - host: foo.bar.com
    http:
      paths:
      - path: /foo
        pathType: Prefix
        backend:
          service:
            name: service1
            port:
              number: 4200
      - path: /bar
        pathType: Prefix
        backend:
          service:
            name: service2
            port:
              number: 8080

因此您的清单文件可能如下所示:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
    name: lightning-ingress
    namespace: default
spec:
  rules:
  - host: [your host name here]
    http:
      paths:
      - path: /storage
        pathType: Prefix
        backend:
          service:
            name: minio
            port:
              number: 9000
      - path: /portal
        pathType: Prefix
        backend:
          service:
            name: oscar
            port:
              number: 8080

参考:Kubernetes doc