无法将静态IP地址分配给Google Cloud中的负载均衡器

时间:2019-06-27 14:28:07

标签: kubernetes google-kubernetes-engine gcloud traefik traefik-ingress

我正在尝试为我的Traefik入口负载均衡器分配一个静态IP地址,但始终在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

我确实注意到所有静态内容都在“保留”中,而不是在使用中

# 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

2 个答案:

答案 0 :(得分:0)

当您将Service规范与type: LoadBalancer配合使用时,Kubernetes引擎将使用Google Cloud负载平衡器(GCLB)为您自动配置TCP(!)负载平衡器。

因此,将loadBalancerIP: 35.185.139.44kubectl apply --filename=...删除,不带它,稍等片刻,然后kubectl get service/traefik-service,您应该看到LB为您提供了服务。

或者:

kubectl get services \
--selector=app=traefik-gke-demo,tier=reverse-proxy \
--output=jsonpath="{.status.loadBalancer.ingress[0].ip}"

和以下某些变体以确认已配置负载均衡器:

gcloud compute forwarding-rules list \
--format="value(IPAddress) \
--project=[[YOUR-PROJECT]]

NB 使用这种方式Service将提供一个TCP负载均衡器。如果您希望使用HTTP | L7负载均衡器,则应使用Ingress

答案 1 :(得分:0)

服务声明正确, 运行Kubernetes v1.1的Google Container Engine支持loadBalancerIP,您只需要事先为项目创建静态IP,即

gcloud compute addresses create traefik-static-lb

gcloud compute addresses list

保留后,创建LB服务

UPD:

以下是为我的LB服务分配了静态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