LoginSignup
0
0

More than 3 years have passed since last update.

[GKE] TCP/UDP が混在するロードバランサをデプロイできない

Posted at

概要

  • GKE上では TDP/UDP が混在したL4ロードバランサ(spec.type: loadBalancer)を作成できない。
  • プロトコル毎(TCP用、UDP用)に L4 ロードバランサを作成する。
  • それぞれのロードバランサには、異なる IP アドレスが割り当てられてしまう。
  • 内部ロードバランサの場合、割り当てたい内部IPアドレスを共有アドレスとして予約しておくことで、それぞれのロードバランサに同じIPアドレスを VIP として割り当てることができる。

現象

GKE 上で稼働している Zabbix Server へ SNMPTrapd を実装する必要があり、次のように Service マニフェストファイルに snmptrapd (162/udp) を追加しました。

svc.yaml
apiVersion: v1
kind: Service
metadata:
  name: svc-zabbix
  annotations:
    cloud.google.com/load-balancer-type: "Internal"
  namespace: zabbix
  labels:
    run: svc-zabbix
spec:
  type: LoadBalancer
  ports:
  - port: 80
    name: http
    protocol: TCP
    targetPort: 80
  - port: 10051
    name: zabbix-trapper
    protocol: TCP
    targetPort: 10051
  - port: 162
    name: snmptrapd
    protocol: UDP
    targetPort: 162
  selector:
    run: zabbix
  loadBalancerIP: 10.128.1.56

これをデプロイすると cannot create an external load balancer with mix protocols と叱られます。

$ kubectl apply -f svc.yaml
・・・
cannot create an external load balancer with mix protocols

内部IPアドレスをVIPとして予約

次のコマンドで、内部IPアドレスを 共有VIPとして予約します。

ちなみに --purpose オプションは、外部IPアドレスの場合は適用されないようです。(参考

$ gcloud beta compute addresses create zabbix-address \
    --region asia-northeast1 \
    --subnet example-vpc-subnet-1 \
    --addresses 10.128.1.56 \
    --purpose SHARED_LOADBALANCER_VIP

内部IPアドレスが予約できたか確認します。

$ gcloud compute addresses list zabbix-address
NAME             ADDRESS/RANGE  TYPE      PURPOSE  NETWORK  REGION           SUBNET                STATUS
zabbix-address   10.128.1.56    INTERNAL                    asia-northeast1  example-vpc-subnet-1  RESERVED

プロトコル別にロードバランサ作成

TCP、UDP別に Service マニフェストを作成します。

svc.yaml
apiVersion: v1
kind: Service
metadata:
  name: svc-zabbix-tcp
  annotations:
    cloud.google.com/load-balancer-type: "Internal"
  namespace: zabbix
  labels:
    run: svc-zabbix-tcp
spec:
  type: LoadBalancer
  ports:
  - port: 80
    name: http
    protocol: TCP
    targetPort: 80
  - port: 10051
    name: zabbix-trapper
    protocol: TCP
    targetPort: 10051
  selector:
    run: zabbix
  loadBalancerIP: 10.128.1.56
---
apiVersion: v1
kind: Service
metadata:
  name: svc-zabbix-udp
  annotations:
    cloud.google.com/load-balancer-type: "Internal"
  namespace: zabbix
  labels:
    run: svc-zabbix-udp
spec:
  type: LoadBalancer
  ports:
  - port: 162
    name: snmptrapd
    protocol: UDP
    targetPort: 162
  selector:
    run: zabbix
  loadBalancerIP: 10.128.1.56

Service を GKE へデプロイします。

$ kubectl apply -f svc.yaml 
service/svc-zabbix-tcp created
service/svc-zabbix-udp created

同じ 内部IPアドレス(10.128.1.56)が割り当てられた L4 ロードバランサが2つ作成されました。

$ kubectl get svc
NAME            TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)                         AGE
svc-zabbix-tcp  LoadBalancer   10.1.161.66    10.128.1.56   80:32216/TCP,10051:32232/TCP    2m51s
svc-zabbix-udp  LoadBalancer   10.1.162.198   10.128.1.56   162:30825/UDP                   2m51s
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0