Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcloud ingress loadbalancer / static ip

Having set the default gce ingress controller working with ingresses resources set to respond to hostnames

The advantage of having a static ip (in my very current point of view) is that you never wonder where to configure your domain to, it will always remain the same ip; and on the other side you can stick as much service as you want behind it

I'm quite new using this gce loadbalancer, can I rely on it as I would with a static ip (meaning it'll never change) ? Or is there a layer to add to point a static ip to a loadbalancer ?

I'm asking because you can set the ip of a service resource. But I have no clue yet about doing the same with this lbc/ingress combo — assigning a static ip to an ingress ?

I've checked around, there seem to exist some 'forwarding' (static ip to load balancer)… but I'd really appreciate some experienced help on this one, at least to end up understanding it all clearly

Best

like image 308
Ben Avatar asked Oct 19 '16 16:10

Ben


People also ask

How do I assign a static IP to ingress?

To acquire a static IP for the ingress-nginx-controller, simply put it behind a Service of Type=LoadBalancer . Then, update the ingress controller so it adopts the static IP of the Service by passing the --publish-service flag (the example yaml used in the next step already has it set to "ingress-nginx-lb").

How can you get a static IP for a Kubernetes load balancer?

To create a LoadBalancer service with the static public IP address, add the loadBalancerIP property and the value of the static public IP address to the YAML manifest. Create a file named load-balancer-service. yaml and copy in the following YAML. Provide your own public IP address created in the previous step.

Why do we need ingress controller?

An Ingress controller abstracts away the complexity of Kubernetes application traffic routing and provides a bridge between Kubernetes services and external ones. Kubernetes Ingress controllers: Accept traffic from outside the Kubernetes platform, and load balance it to pods (containers) running inside the platform.

Which type of cloud load balancers offer session affinity?

External TCP Proxy Load Balancing supports Session Affinity and offers client IP affinity, which forwards all requests from the same client IP address to the same backend.


1 Answers

Finally I have a working solution. You gotta add an L4 Service using loadBalancerIP: x.x.x.x where you put a previously reserved static IP, and then put a selector that the deployment/RC already has, like this:

UPDATE [Nov-2017]: Static IP should be regional and in the same region as cluster

Service:

apiVersion: v1
kind: Service
metadata:
  name: nginx-ingress-svc
spec:
  type: LoadBalancer
  loadBalancerIP: 104.155.55.37  # static IP pre-allocated.
  ports:
    - port: 80
      name: http
    - port: 443
      name: https
  selector:
    k8s-app: nginx-ingress-lb

Controller:

apiVersion: v1
kind: ReplicationController
metadata:
  name: nginx-ingress-rc
  labels:
    k8s-app: nginx-ingress-lb
spec:
  replicas: 1
  selector:
    k8s-app: nginx-ingress-lb
  template:
    metadata:
      labels:
        k8s-app: nginx-ingress-lb
    spec:
      containers:
      - image: eu.gcr.io/infantium-platform-20/nginx-ingress
        imagePullPolicy: Always
        name: nginx-ingress
        ports:
        - containerPort: 80
          hostPort: 80
        - containerPort: 443
          hostPort: 443
        args:
        - -nginx-configmaps=staging/nginx-staging-config

Solution hint was sourced from this example: https://beroux.com/english/articles/kubernetes/?part=3

Hope this helps.

like image 117
danius Avatar answered Nov 16 '22 01:11

danius