EMQTT 叢集部署 (Deployment + HPA)

用 Deployment 加上 HorizontalPodAutoscaler 部署 EMQTT 叢集的資源清單。適合先跑起來驗證自動擴展行為。

檔案

master.yaml

master 用 NodePort 對外,方便在沒有 LoadBalancer 的環境直接連:

kind: Service
apiVersion: v1
metadata:
  name: emqtt-master
  namespace: emqtt
spec:
  type: NodePort
  ports:
  - nodePort: 30003
    name: dashboard
    port: 18083
    targetPort: 18083
  - nodePort: 30002
    name: mqtt
    port: 1883
    targetPort: 1883

Deployment 固定 1 個 replica,並用 TCP 1883 做 liveness 與 readiness 探測:

livenessProbe:
  tcpSocket:
    port: 1883
  initialDelaySeconds: 5
  timeoutSeconds: 10

mqtt.yaml

工作節點透過 MASTER_NODES 環境變數加入 master 組成叢集,並掛上 HPA 依 CPU 使用率擴展 1~10 個 Pod:

apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: emqtt-scaler
  namespace: emqtt
spec:
  scaleTargetRef:
    kind: Deployment
    name: emqtt
  minReplicas: 1
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      targetAverageUtilization: 50

容器同時開放 Erlang 節點通訊需要的 4369 與 6000-6010。

部署

kubectl create namespace emqtt
kubectl apply -f master.yaml
# 取得 master Pod IP,填進 mqtt.yaml 的 MASTER_NODES
kubectl -n emqtt get pod -o wide
kubectl apply -f mqtt.yaml

# 觀察擴展狀況
kubectl -n emqtt get hpa -w

需要更新的地方

這份清單是為較舊的 Kubernetes 版本寫的,在近期版本上會被拒絕:


← 回到 EMQTT Autoscale

本目錄檔案