簡體   English   中英

使用帶有 Kubernetes 服務的谷歌雲中的外部 IP 將其公開到互聯網

[英]Use External IP in Google cloud with Kubernetes service to expose it to the internet

我有一個 phpmyadmin 服務在 kubernetes 集群上運行。 我想在谷歌雲上保留一個外部 IP(靜態)以與此服務一起使用,以便可以從 Internet 訪問它。 我嘗試在 GCP 上保留 IP 地址並在 kubernetes 服務文件中使用它,如下所示:

apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: /snap/kompose/19/kompose-linux-amd64 convert
    kompose.version: 1.21.0 (992df58d8)
  creationTimestamp: null
  labels:
    io.kompose.service: phpmyadmin
  name: phpmyadmin
spec:
  externalIPs: [xx.xxx.xxx.xxx]  #the external IP from Google cloud
  ports:
  - name: "8080"
    port: 8080
    targetPort: 80
  selector:
    io.kompose.service: phpmyadmin
status:
  loadBalancer: {}

當我指定spec.type: LoadBalancer ,可以使用從type: LoadBalancer生成的默認 IP 地址從 Internet 訪問該服務type: LoadBalancer

我試圖通過允許端口 8080 上的 Ingress 來更改外部 IP 地址的防火牆規則,但這不起作用。

而不是設置exteranlIPs ,您應該設置spec.loadBalancerIP ,其中spec.typeLoadBalancer值:

apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: /snap/kompose/19/kompose-linux-amd64 convert
    kompose.version: 1.21.0 (992df58d8)
  creationTimestamp: null
  labels:
    io.kompose.service: phpmyadmin
  name: phpmyadmin
spec:
  ports:
  - name: "8080"
    port: 8080
    targetPort: 80
  selector:
    io.kompose.service: phpmyadmin
  type: LoadBalancer
  loadBalancerIP: "YOUR_IP_ADDRESS"
status:
  loadBalancer: {}

請注意,通過外部靜態 IP 公開您的 Pod 僅支持區域負載平衡流量,因此您保留的靜態 IP 地址需要是區域性的。

對於全局 IP 地址,您需要通過Ingress對象公開HTTP(s) 負載均衡器

防火牆規則在實例級別應用。 它們無法阻止流量到達負載均衡器本身。

參考: https : //cloud.google.com/load-balancing/docs/https/#firewall_rules

默認情況下,您的 GKE LB 服務可能正在創建HTTP負載均衡器,也許您可​​以查看NLB 負載均衡器https : //cloud.google.com/load-balancing/docs/choosing-load-balancer#summary-of-google-雲負載均衡器

所有端口: https : //cloud.google.com/kubernetes-engine/docs/how-to/service-parameters#all_ports

apiVersion: v1
kind: Service
metadata:
  name: helloworld
  labels:
    app: helloworld
  annotations:
    cloud.google.com/neg: '{"exposed_ports": {"8080":{}}}'
spec:
  ports:
  - name: 8080-8080
    port: 8080
    protocol: TCP
    targetPort: 8080
  selector:
    app: helloworld
  # Use LoadBalancer type instead of ClusterIP
  type: LoadBalancer

示例: https : //spring-gcp.saturnism.me/deployment/kubernetes/load-balancing/external-load-balancing

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM