kubernetes - 如何将网关绑定(bind)到特定的命名空间?

标签 kubernetes istio

我有以下情况:
enter image description here

  • 当用户一个 在中输入地址 foo.example1.example.com
    浏览器,那么它应该调用服务在命名空间中
    示例1 .
  • 当用户在中输入地址 foo.example1.example.com
    浏览器,那么它应该调用服务在命名空间中
    示例2 .

  • 我正在使用 istio,问题是,如何配置网关,即绑定(bind)特定于命名空间:

    看一个 istio 网关配置的例子:
      $ kubectl apply -f - <<EOF
      apiVersion: networking.istio.io/v1alpha3
      kind: Gateway
      metadata:
        name: ns_example1
      spec:
        selector:
          istio: ingressgateway # use Istio default gateway implementation
        servers:
        - port:
            number: 80
            name: http
            protocol: HTTP
          hosts:
          - "example1.example.com"
      EOF
    

    当我部署网关时,它将应用于当前命名空间,但我想指定一个命名空间。

    如何将网关分配给特定的命名空间?

    最佳答案

    我认为这是 link应该回答你的问题。

    有很多东西是你不需要的,但有一些想法你想应用到你的 istio 集群。

    所以你需要 1 个网关和 2 个虚拟服务。

    apiVersion: networking.istio.io/v1alpha3
    kind: Gateway
    metadata:
      name: foocorp-gateway
      namespace: default
    spec:
      selector:
        istio: ingressgateway # use istio default ingress gateway
      servers:
      - port:
          number: 80
          name: http-example1
          protocol: HTTP
        hosts:
        - "example1.example.com"
      - port:
          number: 80
          name: http-example2
          protocol: HTTP
        hosts:
        - "example2.example.com"
    
    apiVersion: networking.istio.io/v1alpha3
    kind: VirtualService
    metadata:
      name: example1
      namespace: ex1
    spec:
      hosts:
      - "example1.example.com"
      gateways:
      - foocorp-gateway
      http:
      - match:
        - uri:
            exact: /
        route:
        - destination:
            host: example1.ex1.svc.cluster.local
            port:
              number: 80
    ---
    apiVersion: networking.istio.io/v1alpha3
    kind: VirtualService
    metadata:
      name: example2
      namespace: ex2
    spec:
      hosts:
      - "example2.example.com"
      gateways:
      - foocorp-gateway
      http:
      - match:
        - uri:
            exact: /
        route:
        - destination:
            host: example2.ex2.svc.cluster.local
            port:
              number: 80
    

    编辑

    您可以在命名空间 ex1 和 ex2 中创建网关,然后只需更改虚拟服务中的网关字段,它应该可以工作。

    记得添加命名空间/网关,不仅仅是网关名称,比如 there .
    gateways:
      - some-config-namespace/gateway-name
    

    让我知道这是否对您有帮助。

    关于kubernetes - 如何将网关绑定(bind)到特定的命名空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59576218/

    相关文章:

    amazon-web-services - 在 self 管理的 Kubernetes 上获取 Istio 网关的外部 IP

    kubernetes - 如何在 Kubernetes 中实现粘性 session 的金丝雀发布?

    kubernetes - 在kubernetes pod中将URL解析为其他URL

    docker - Bazel - 在 Monorepo 中构建、推送、部署 Docker 容器到 Kubernetes

    nginx - 在 kubernetes 中使用 nginx ingress 时是否需要 nginx 镜像?

    Kubernetes - 获取代理服务的 pod 的 IP

    kubernetes - Istio:sidecar EnvoyFilter workloadSelector 未过滤

    https - Istio 网关无法通过 HTTPS 连接

    kubernetes - 在 kubernetes cronjob 中指定角色

    docker - Kubernetes 挂载的卷具有 root 所有权