我将此service.yaml部署到了我的集群:
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
是我的公共IP地址。但出于某种原因,我的公共IP无法访问此服务。现在应该由GCP支持。
如果我使用公开它可以工作,但打开所有流量,我为什么我想使用loadBalancerSourceRanges
kubectl expose deployment mydeployment --type=LoadBalancer --port 8888 --target-port 8888
尝试使用注释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"
...
...
现在GKE有防火墙。您需要接受您的IP。
iptables -A INPUT -p tcp -s YOUR_IP -j ACCEPT
iptables -A OUTPUT -p tcp -s YOUR_IP -j ACCEPT