Reserve static IP address for k8s external service

3/18/2019

I want to reserve static IP address for my k8s exposed service. If I am not mistaken when I expose the k8s service it gets the random public IP address. I redeploy my app often and the IP changes. But I want to get permanent public IP address. My task is to get my application via permanent IP address (or DNS-name).

-- malcolm
google-kubernetes-engine
kubernetes

1 Answer

3/18/2019

This is cloud provider specific, but from the tag on your question it appears you are using Google Cloud Platform's Kubernetes Engine (GKE). My answer is specific for this situation.

From the Setting up HTTP Load Balancing with Ingress tutorial:

gcloud compute addresses create web-static-ip --global

And in your Ingress manifest:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: basic-ingress
  annotations:
    kubernetes.io/ingress.global-static-ip-name: "web-static-ip"
spec:
  backend:
    serviceName: web
    servicePort: 8080

You can do something similar if you using Service instead of Ingress:

apiVersion: v1
kind: Service
metadata:
  name: helloweb
  labels:
    app: hello
spec:
  type: LoadBalancer
  loadBalancerIP: "web-static-ip"
  selector:
    app: hello
    tier: web
  ports:
  - port: 80
    targetPort: 8080
-- Janos Lenart
Source: StackOverflow