Kubernetes ingress-nginx LoadBalancer指向云存储桶

时间:2019-04-21 01:04:05

标签: kubernetes load-balancing gcloud nginx-ingress

我使用nginx-ingress-controller:0.24.1Inspired by

我想将DNS A记录设置为LB IP地址,以便将其连接到在根目录中和后端具有公共index.html的Google云公共存储桶(my-back-end-bucket)通过另一个网址规则。

kind: Service
apiVersion: v1
metadata:
  name: ingress-nginx
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
spec:
  externalTrafficPolicy: Local
  type: LoadBalancer
  selector:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
  ports:
    - name: http
      port: 80
      targetPort: http
    - name: https
      port: 443
      targetPort: https

---

kind: Service
apiVersion: v1
metadata:
  name: google-storage-buckets-service
  namespace: ingress-nginx
spec:
  type: ExternalName
  externalName: storage.googleapis.com

---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: proxy-assets-ingress
  namespace: ingress-nginx
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /my.bucket.com
    nginx.ingress.kubernetes.io/secure-backends: "true"
    nginx.ingress.kubernetes.io/upstream-vhost: "storage.googleapis.com"
spec:
  rules:
    - http:
        paths:
          - path: /*
            backend:
              serviceName: google-storage-buckets-service
              servicePort: 443
          - path: /c/
            backend:
              serviceName: hello-world-service
              servicePort: 8080

到达https://my.ip.add.ress/c时,两个输出均得到:世界,您好!存储桶内容。

“您好,世界!” 组成了 hello-world-service

存储桶的index.html文件中的

“存储桶内容”

问题:如何使其工作,通过 ip / -我获得了一个存储桶内容 以及 ip / c -后端响应内容?

1 个答案:

答案 0 :(得分:1)

您可以将入口分为两个,其中一个定义了path: /*并带有必要的注释,另一个定义了path: /c/

单个入口的问题在于,您要应用于path: /*的注释也仅应用于其他路径。