Assign a Static IP Address to a Kubernetes Service

In IONOS Managed Kubernetes, LoadBalancer service creation does not provision an external load balancer. Instead, IONOS automatically reserves a static public IP address and assigns it as a secondary IP address to one of your worker nodes. This node acts as an ingress node, accepting incoming traffic and forwarding it to the correct pod using kube-proxy.

Functionality of LoadBalancer services in IONOS Managed Kubernetes

  1. When a LoadBalancer service is created, IONOS either assigns an existing pre-reserved static IP address or automatically reserves a new one.

  2. This IP address is attached as a secondary IP address to one of the worker nodes in the cluster.

  3. The designated ingress node handles incoming traffic.

  4. If the target pod runs on a different node, kube-proxy routes the traffic to the correct destination.

Reserve a static IP address

You can obtain a static IP address in either of the following ways:

  • Pre-reserving a static IP address: You can manually reserve an IP address beforehand and reference it in your service manifest. This ensures that the IP address remains assigned even if the service is deleted.

  • Automatic Reservation: If you do not specify a loadBalancerIP, IONOS dynamically reserves an IP address. However, this IP address is released when the service is deleted.

Example: Deploy an echo server with a static IP address

To demonstrate the behavior of the IONOS LoadBalancer service, we will deploy an echo server that returns request details useful for verifying traffic routing.

1

Deploy the echo server: The following deployment runs two instances of the echo server to demonstrate traffic forwarding:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: echo-server
spec:
  replicas: 2
  selector:
    matchLabels:
      app: echo-server
  template:
    metadata:
      labels:
        app: echo-server
    spec:
      containers:
        - name: echo-server
          image: ealen/echo-server
          ports:
            - containerPort: 80
2

Create the LoadBalancer service: Use either of the following options to create a LoadBalancer service:

Option 1: Use a pre-reserved static IP address

If you have manually reserved a static IP address in your IONOS account, you can assign it explicitly in the service manifest using the following code:


apiVersion: v1
kind: Service
metadata:
  name: echo-service
spec:
  type: LoadBalancer
  loadBalancerIP:RESERVED-IP (Remember to mention your pre-reserved static IP address.)
  selector:
    app: echo-server
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
Option 2: Automatically assign a static IP address

If you do not specify a loadBalancerIP, IONOS dynamically reserves an IP address. When a static IP address is assigned dynamically, it will be released once the service is deleted.


apiVersion: v1
kind: Service
metadata:
  name: echo-service
spec:
  type: LoadBalancer
  selector:
    app: echo-server
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
3

Verify the Assigned Static IP Address: Check the assigned external IP address after service creation:

kubectl get service echo-service
4

Test the Echo Server: You can send a request to the assigned IP address to verify traffic routing:

curl http://85.215.190.220 

Summary

This setup ensures a stable external IP address for applications without requiring an additional load balancer.

  • IONOS reserves a static IP address for each LoadBalancer service.

  • You can either pre-reserve an IP address or let IONOS assign one automatically.

  • The static IP address is attached to an ingress node and used to route traffic via kube-proxy.

  • If you do not specify a loadBalancerIP, the IP address is automatically released when you delete the service.

Last updated

Was this helpful?