简体   繁体   English

Kubernetes:如何在不更改外部IP地址的情况下更新名称空间?

[英]Kubernetes: How to update namespace without changing external IP address?

How to update namespace without changing External-IP of the Service? 如何在不更改服务外部IP的情况下更新名称空间?

Initially, it was without namespace and it was deployed: 最初,它没有名称空间,并且已部署:

kind: Service
metadata:
  name: my-app
  labels:
    app: my-app
spec:
  type: LoadBalancer
  ports:
    port: 80
    protocol: TCP
  selector:
    app: my-app

It creates External-IP address and it was pointed to the DNS. 它创建外部IP地址,并指向DNS。 Now I would like to update the Namespace to keep it more organised. 现在,我想更新命名空间以使其更有条理。 So I have created the namespace. 因此,我创建了名称空间。

apiVersion: v1
kind: Namespace
metadata:
  name: my-namespace

and I have updated the service with a namespace. 并且我已经使用命名空间更新了该服务。

kind: Service
metadata:
  name: my-app
  namespace: my-namespace
  labels:
    app: my-app
spec:
  type: LoadBalancer
  ports:
    port: 80
    protocol: TCP
  selector:
    app: my-app

The above file creates another Service in my-namespace and the External-IP is not the same. 上面的文件在my-namespace创建了另一个Service,而External-IP不相同。 Is there a way to update the namespace without recreating? 有没有一种方法可以在不重新创建的情况下更新名称空间?

Please let me know if you need any information. 如果您需要任何信息,请告诉我。 Thanks! 谢谢!

some cloud providers allow you to specify external ip of a service with https://kubernetes.io/docs/concepts/services-networking/service/#external-ips if you can ake use of this, you should be able to achieve what you need. 一些云提供商允许您使用https://kubernetes.io/docs/concepts/services-networking/service/#external-ips指定服务的外部ip,如果可以使用它的话,您应该能够实现你需要。 This will not be a zero downtime operation though as you'll first need to delete the current service and recreate it under different namespace with externalIP specified. 这不是零停机时间操作,因为您首先需要删除当前服务,并在指定了externalIP的其他命名空间下重新创建它。

It seems that what you are after is a static public IP address, that is, one that you have reserved and outlives your cluster. 您所追求的似乎是一个静态的公共IP地址,即您已保留的IP地址,并且该地址的寿命超过了群集。 If you had one of these, you would be able to specify it for your LoadBalancer either as @Radek mentions above, or possibly with a provider-specific annotation. 如果您具有其中之一,则可以为LoadBalancer指定它,如上面@Radek所述,或者可以使用提供程序特定的注释。 Then you would be able to move the IP address between LoadBalancer s (same applies for Ingress too). 然后,您将能够在LoadBalancer之间移动IP地址(同样适用于Ingress )。

However it seems you have not yet allocated a static public IP yet. 但是,您似乎尚未分配静态公共IP。 It may be a good time to do this, but as Azure doesn't appear to allow you to “promote” a dynamic IP to a static IP it won't directly help you here (*). 这可能是个好时机,但是由于Azure似乎不允许您将动态IP“提升”为静态IP,因此这里并不能直接为您提供帮助(*)。

So you're left with creating a new LoadBalancer resource with a new public IP. 因此,您剩下的工作就是使用新的公共IP创建新的LoadBalancer资源。 To aid transition and avoid downtime, you could use an external DNS entry to switch users over from 1st to 2nd LoadBalancer IP addresses, which can be done seamlessless and without downtime if you set things up correctly. 为了帮助过渡并避免停机,您可以使用外部DNS条目将用户从第1个LoadBalancer IP地址切换到第2个,如果设置正确,则可以无缝无缝地进行,而无需停机。 However does take a bit of time to transition: only once the DNS TTL period is done, is it safe to delete the first LoadBalancer . 但是,过渡确实需要一些时间:仅在完成DNS TTL周期后,才可以安全删除第一个LoadBalancer

If you don't have an external DNS, this illustrates why it's a good idea to set it up. 如果您没有外部DNS,这说明了为什么设置它是一个好主意。

(*) GCP does allow you to do this, I doubt AWS does. (*)我怀疑AWS允许GCP允许您这样做。

The best way to address this issue is to introduce nginx ingress controller. 解决此问题的最佳方法是引入nginx入口控制器。 Let Externel LB route the calls to ingress controller. 让Externel LB将呼叫路由到入口控制器。 just update the ingress rules with correct service mapping. 只需使用正确的服务映射来更新入口规则。

the advantage is that you can expose any number of apps/service from single external IP via ingress. 优点是您可以通过入口从单个外部IP公开任何数量的应用程序/服务。 Without ingress you will have to setup one external LB for each application/service that you want to expose to outside world 没有入口,您将必须为要向外界公开的每个应用程序/服务设置一个外部LB。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM