k8s 部署 emqx-安装 EMQX

时间:2024-10-24 19:41:42
apiVersion: v1
kind: Namespace
metadata:
  name: ns-emqx
  
--- 
apiVersion: apps.emqx.io/v2beta1
kind: EMQX
metadata:
   name: emqx
   namespace: ns-emqx
spec:
   image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/emqx/emqx:5.8.1

查看 EMQX 的 k8s service

kubectl get svc -n ns-emqx 

上面这种方式部署的一个无头服务的EMQX。下面通过 LoadBalancer 访问 EMQX 集群

apiVersion: v1
kind: Namespace
metadata:
  name: ns-emqx

--- 
apiVersion: apps.emqx.io/v2beta1
kind: EMQX
metadata:
  name: emqx
  namespace: ns-emqx
spec:
  image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/emqx/emqx:5.8.1
  listenersServiceTemplate:
    spec:
      type: LoadBalancer
  dashboardServiceTemplate:
    spec:
      type: LoadBalancer

再次查看 EMQX 的 k8s service

kubectl get svc -n ns-emqx 

结果

NAME             TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                                                       AGE
emqx-dashboard   NodePort    10.100.118.67    <none>        18083:31321/TCP                                               19s
emqx-headless    ClusterIP   None             <none>        4370/TCP,5369/TCP                                             40s
emqx-listeners   NodePort    10.101.198.122   <none>        8883:31407/TCP,1883:31263/TCP,8083:31433/TCP,8084:32283/TCP   19s

EMQX Operator 会创建两个 EMQX Service 资源,一个是 emqx-dashboard,一个是 emqx-listeners,分别对应 EMQX 控制台和 EMQX 监听端口。

通过 NodeIP + 端口 就可以访问EMQX的控制台。这里是http://127.0.0.1:31321;用户和密码:admin/public