Kubernetes Ingress-nginx LoadBalancer指向云存储桶 [英] Kubernetes ingress-nginx LoadBalancer pointing to cloud bucket

查看:95
本文介绍了Kubernetes Ingress-nginx LoadBalancer指向云存储桶的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 nginx-ingress-controller:0.24.1 (灵感来自)

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

I would like to set a DNS A record to LB IP address, so it would connect it to the Google cloud public bucket (my-back-end-bucket) that has public index.html in the root AND to the back-end by another url rule.

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 -获得了两个输出:您好,世界!存储桶内容.

By reaching https://my.ip.add.ress/c - got both outputs: Hello, world! bucket content.

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

存储桶内容"

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

Question: how to make it work so, that by ip/ - I got a bucket content and by ip/c - back-end response content ?

推荐答案

您可以将入口分为两个,一个入口定义带有必需注释的path: /*,另一个入口定义path: /c/.

You can split your ingress into two where one defines path: /* with necessary annotation and another ingress that defines path: /c/.

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

The problem with your single ingress is that its annotations that you want to apply to path: /* only gets applied to other paths as well.

这篇关于Kubernetes Ingress-nginx LoadBalancer指向云存储桶的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆