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

2/15/2019

How to update namespace without changing External-IP of the Service?

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. 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. Is there a way to update the namespace without recreating?

Please let me know if you need any information. Thanks!

-- Ramesh Murugesan
kubernetes

3 Answers

2/15/2019

The best way to address this issue is to introduce nginx ingress controller. Let Externel LB route the calls to ingress controller. 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. Without ingress you will have to setup one external LB for each application/service that you want to expose to outside world

-- P Ekambaram
Source: StackOverflow

2/15/2019

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. 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.

-- Radek 'Goblin' Pieczonka
Source: StackOverflow

2/17/2019

It seems that what you are after is a static public IP address, that is, one that you have reserved and outlives your cluster. 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. Then you would be able to move the IP address between LoadBalancers (same applies for Ingress too).

However it seems you have not yet allocated a static public IP yet. 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 (*).

So you’re left with creating a new LoadBalancer resource with a new public IP. 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. 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.

If you don’t have an external DNS, this illustrates why it’s a good idea to set it up.

(*) GCP does allow you to do this, I doubt AWS does.

-- Paul Annetts
Source: StackOverflow