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

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

问题描述

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

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

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!" 形成 hello-world-service

bucket content"来自bucket' index.html 文件

"bucket content" from the bucket' index.html file

问题:如何使它工作,通过 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天全站免登陆