从k8s入口动态添加/删除命名主机 [英] Dynamically adding/removing named hosts from k8s ingress

查看:86
本文介绍了从k8s入口动态添加/删除命名主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在GKE上建立一个k8s集群.通配符DNS *.server.com将指向Ingress控制器.在集群内部,将有Web服务器Pod,每个Pod都提供独特的服务. Ingress控制器将使用服务器名称路由到各种服务.

I'm setting up a k8s cluster on GKE. A wildcard DNS *.server.com will point to a Ingress controller. Internally to the cluster, there will be webserver pods, each exposing a unique service. The Ingress controller will use the server name to route to the various services.

几乎每天都会创建和销毁服务器.我想知道是否有一种方法可以在不编辑命名服务器的整个列表的情况下从入口控制器中添加和删除命名服务器.

Servers will be created and destroyed on a nearly daily basis. I'd like to know if there's a way to add and remove a named server from the ingress controller without editing the whole list of named servers.

推荐答案

似乎您打算在单个负载均衡器(==单个Ingress资源)上托管多个域名.如果不是,则此答案不适用.

It appears like you're planning to host multiple domain names on a single Load Balancer (==single Ingress resource). If not, this answer doesn't apply.

您可以通过为Ingress配置一长串域名来实现此目的,例如:

You can do this by configuring Ingress with a long list of domain names like:

spec:
  rules:
  - host: cats.server.com
    http:
      paths:
      - path: /*
        backend:
          serviceName: cats
          servicePort: 8080
  - host: dogs.server.com
    http:
      paths:
      - path: /*
        backend:
          serviceName: dogs
          servicePort: 8080
  - [...]

如果这是您的意图,如果不编辑整个列表,并且每次都将其应用于集群,就无法做到这一点.

If that's your intention, there's no way of doing this without editing this whole list and applying it to the cluster every time.

您可以构建一个工具来构建此清单文件,然后应用更改. Ingress控制器足够聪明,如果现有域仍在列表中,它们将不会出现停机情况.

You can build a tool to construct this manifest file, then apply the changes. The Ingress controller is smart enough that existing domains will not see a downtime if they're still on the list.

但是,从列表中删除的域也将从负载均衡器的URL映射中删除,因此不再接受流量.

However the domains you removed from the list will also be removed from the URL Map of the load balancer and hence stop accepting the traffic.

这篇关于从k8s入口动态添加/删除命名主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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