参考文档:

https://www.emqx.io/docs/zh/v5.0/deploy/cluster/intro.html //EMQX 介绍
https://www.emqx.io/docs/zh/v5.0/deploy/cluster/intro.htmlhttps://www.likecs.com/show-307827704.html

环境介绍:

● K3s集群:由3个节点组成的K3s集群
● Kuboard:k8s可视化管理工具

EMQX单节点部署

1、基本信息

在这里插入图片描述

2、容器信息

在这里插入图片描述

3、服务和路由

在这里插入图片描述

至此单个EMQX已部署好

EMQX集群部署

查阅官方文档可知EMQX支持Kubernetes 服务自动集群

1、配置环境变量

在这里插入图片描述

2、增加Pod副本

在这里插入图片描述

3、验证

访问EMQX管理界面
在这里插入图片描述
若node个数与副本个数一致 则说明集群成功

特别注意:如果是新环境搭建,需要先给容器所在的命名空间赋权,因为EMQX在K8S上自动发现集权,需要访问K8S的ApiServer,如果权限不足会报错。
附录:

---
apiVersion: apps/v1
kind: StatefulSet
metadata:
 annotations: {}
 labels:
 k8s.kuboard.cn/layer: cloud
 k8s.kuboard.cn/name: emqx
 name: emqx
 namespace: default
 resourceVersion: '4217757'
spec:
 podManagementPolicy: OrderedReady
 replicas: 1
 revisionHistoryLimit: 10
 selector:
 matchLabels:
 k8s.kuboard.cn/layer: cloud
 k8s.kuboard.cn/name: emqx
 serviceName: emqx
 template:
 metadata:
 annotations:
 kubectl.kubernetes.io/restartedAt: '2022-07-27T15:46:52+08:00'
 creationTimestamp: null
 labels:
 k8s.kuboard.cn/layer: cloud
 k8s.kuboard.cn/name: emqx
 spec:
 containers:
 - env:
 - name: EMQX_NAME
 value: emqx
 - name: EMQX_CLUSTER__DISCOVERY
 value: k8s
 - name: EMQX_CLUSTER__K8S__APP_NAME
 value: emqx
 - name: EMQX_CLUSTER__K8S__SERVICE_NAME
 value: emqx
 - name: EMQX_CLUSTER__K8S__APISERVER
 value: 'https://kubernetes.default.svc:443'
 - name: EMQX_CLUSTER__K8S__NAMESPACE
 value: default
 image: 'emqx/emqx:latest'
 imagePullPolicy: IfNotPresent
 name: emqx
 resources: {}
 terminationMessagePath: /dev/termination-log
 terminationMessagePolicy: File
 dnsPolicy: ClusterFirst
 restartPolicy: Always
 schedulerName: default-scheduler
 securityContext: {}
 terminationGracePeriodSeconds: 30
 updateStrategy:
 rollingUpdate:
 partition: 0
 type: RollingUpdate
status:
 availableReplicas: 1
 collisionCount: 0
 currentReplicas: 1
 currentRevision: emqx-569d7cdbb
 observedGeneration: 7
 readyReplicas: 1
 replicas: 1
 updateRevision: emqx-569d7cdbb
 updatedReplicas: 1

---
apiVersion: v1
kind: Service
metadata:
 annotations: {}
 labels:
 k8s.kuboard.cn/layer: cloud
 k8s.kuboard.cn/name: emqx
 name: emqx
 namespace: default
 resourceVersion: '938'
spec:
 clusterIP: 10.43.237.4
 clusterIPs:
 - 10.43.237.4
 externalTrafficPolicy: Cluster
 internalTrafficPolicy: Cluster
 ipFamilies:
 - IPv4
 ipFamilyPolicy: SingleStack
 ports:
 - name: yrmtyj
 nodePort: 30904
 port: 18083
 protocol: TCP
 targetPort: 18083
 - name: nz8btg
 nodePort: 31875
 port: 1883
 protocol: TCP
 targetPort: 1883
 - name: der2mz
 nodePort: 30183
 port: 8083
 protocol: TCP
 targetPort: 8083
 selector:
 k8s.kuboard.cn/layer: cloud
 k8s.kuboard.cn/name: emqx
 sessionAffinity: None
 type: NodePort
status:
 loadBalancer: {}
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐