loadBalancerSourceRanges not working for google kubernetes cluster

11/24/2018

I deployed this service.yaml to my cluster:

apiVersion: v1
kind: Service
metadata:
  name: myapp
spec:
  type: LoadBalancer
  ports:
  - protocol: TCP
    port: 8888
    targetPort: 8888
  loadBalancerSourceRanges:
  - 123.123.123.123/32

123.123.123.123/32 is my public IP address. But this service is not accessible from my public IP for some reason. This is supposed to be supported by GCP now.

If I use expose it works but opens up ALL traffic which I why I want to use loadBalancerSourceRanges

kubectl expose deployment mydeployment --type=LoadBalancer --port 8888 --target-port 8888
-- red888
google-cloud-platform
google-compute-engine
google-kubernetes-engine
kubernetes

2 Answers

4/25/2019

try using the annotation service.beta.kubernetes.io/load-balancer-source-ranges

apiVersion: v1
kind: Service
metadata:
  name: morgua-api-loadbalancer
  annotations:
    service.beta.kubernetes.io/load-balancer-source-ranges: "130.211.204.1/32, 173.245.48.0/20,103.21.244.0/22,103.22.200.0/22,103.31.4.0/22,141.101.64.0/18,108.162.192.0/18,190.93.240.0/20,190.93.240.0/20,188.114.96.0/20,197.234.240.0/22,198.41.128.0/17,162.158.0.0/15,104.16.0.0/12,172.64.0.0/13,131.0.72.0/22"
...
...
-- Jeryl Cook
Source: StackOverflow

4/18/2019

Now in GKE has Firewall. You need to accept your IP.

iptables -A INPUT -p tcp -s YOUR_IP -j ACCEPT
iptables -A OUTPUT -p tcp -s YOUR_IP -j ACCEPT
-- NguyenHung
Source: StackOverflow