I am trying to assign a static IP address to my Traefik ingress load balancer, but always get the same response on Google Cloud:
Error creating load balancer (will retry): failed to ensure load balancer for service default/traefik-service: requested ip "35.185.139.44" is neither static nor assigned to the LB
coffee:gke Steven$ glcoud compute addresses list
I do notice all static are in the RESERVED and non say IN USE
# Declare Traefik ingress service
kind: Service
apiVersion: v1
metadata:
name: traefik-service
spec:
selector:
app: traefik-gke-demo
tier: reverse-proxy
ports:
- port: 80
name: http
- port: 443
name: https
- port: 8080
name: admin
type: LoadBalancer
loadBalancerIP: 35.185.xx.xx
Service declaration is correct, Google Container Engine running Kubernetes v1.1 supports loadBalancerIP
, you just need to created static IP for your project beforehand, i.e.
gcloud compute addresses create traefik-static-lb
gcloud compute addresses list
Once reserved, create LB service
UPD:
Here is an example of my LB service with assigned static IP:
sukhoversha@sukhoversha:~/GCP$ gcloud compute addresses list
NAME ADDRESS/RANGE TYPE PURPOSE NETWORK REGION SUBNET STATUS
test-static-ip 35.198.94.139 EXTERNAL europe-west3 IN_USE
sukhoversha@sukhoversha:~/GCP$ kk get svc rabbitmq-management
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
rabbitmq-management LoadBalancer 10.59.241.225 35.198.94.139 15672:31728/TCP 4d
sukhoversha@sukhoversha:~/GCP$ kk get svc rabbitmq-management -oyaml
apiVersion: v1
kind: Service
metadata:
labels:
app: rabbitmq
name: rabbitmq-management
namespace: default
spec:
clusterIP: 10.59.241.225
externalTrafficPolicy: Cluster
loadBalancerIP: 35.198.94.139
ports:
- name: http
nodePort: 31728
port: 15672
protocol: TCP
targetPort: 15672
selector:
app: rabbitmq
sessionAffinity: None
type: LoadBalancer
Kubernetes Engine will auto-magically provision a TCP (!) load-balancer for you using the Google Cloud Load-Balancer (GCLB) when you apply a Service
spec with type: LoadBalancer
So, remove loadBalancerIP: 35.185.139.44
and kubectl apply --filename=...
without it, wait briefly and then kubectl get service/traefik-service
and you should see that the LB provisions the service for you.
Alternatively:
kubectl get services \
--selector=app=traefik-gke-demo,tier=reverse-proxy \
--output=jsonpath="{.status.loadBalancer.ingress[0].ip}"
and some variant of the following to confirm the load-balancer is provisioned:
gcloud compute forwarding-rules list \
--format="value(IPAddress) \
--project=[[YOUR-PROJECT]]
NB Using Service
this way will provision a TCP load-balancer. If you would prefer an HTTP|L7 load-balancer, then you should use an Ingress
.