Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to access EMQ X in Kubernetes cluster

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to access EMQ X in Kubernetes cluster". In daily operation, I believe many people have doubts about how to access EMQ X in Kubernetes cluster. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to access EMQ X in Kubernetes cluster". Next, please follow the editor to study!

Ingress introduction

Ingress exposes HTTP and HTTPS routes from outside the cluster to services within the cluster. Traffic routing is controlled by rules defined on the Ingress resource. A simple example of the official website is as follows:

Ingress provides services with URL for external access, load balancer traffic, and TLS/SSL termination capabilities. Ingress can be simply understood as a service of a service, which specifies the rules for forwarding requests through independent Ingress objects, and routes requests to the corresponding services.

In order for Ingress resources to work, the cluster must have a running Ingress controller. NGINX Ingress Controller is a controller supported and maintained by Kubernetes.

This article focuses on how to access EMQ X in a Kubernetes cluster through NGINX Ingress Controller.

Prepare for

Before you begin, make sure that you have set up an available Kubernetes cluster. The example in this article is based on Aliyun Standard Edition managed cluster.

Install EMQ X

Refer to emqx charts and use Helm for installation

$helm repo add emqx https://repos.emqx.io/charts$ kubectl create ns my-emqx$ helm install my-emqx emqx/emqx-n my-emqx

Make sure the pod is in the running state

$kubectl get pod-n my-emqxNAME READY STATUS RESTARTS AGEmy-emqx-0 1 my-emqxNAME READY STATUS RESTARTS AGEmy-emqx-0 1 Running 0 97smy-emqx-1 1 Running 0 73smy-emqx-2 1 1 Running 0 51s

View service

$kubectl get svc-n my-emqxNAME TYPE CLUSTER-IP EXTERNAL-IP PORT (S) AGEmy-emqx ClusterIP 172.21.5.160 1883 etc. 18083/TCP 5mmy-emqx-headless ClusterIP None 1883pm 8883pm 8081max TCP 8083pm 8083max TCP 8084max TCP 18083max TCP 18083max TCP 4370max NGINX Ingress Controller 5m deployment

Refer to Installation Guide and choose different configurations for installation according to different situations, or you can install it through Helm.

$helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx$ helm repo update$ helm install my-release ingress-nginx/ingress-nginx

Because this article is based on Ali Cloud cluster, you can directly select the component installation.

View service

$Kubectl get nginx-ingress-lb svc-n kube-systemNAME TYPE CLUSTER-IP EXTERNAL-IP PORT (S) nginx-ingress-lb LoadBalancer 172.21.6.205 47.99.187.164 80:30639/TCP 443:30396/TCP 3m12s creates Ingress object # ingress.yamlapiVersion: extensions/v1beta1kind: Ingressmetadata: annotations: nginx.ingress.kubernetes.io/proxy-read-timeout: "3600" nginx.ingress.kubernetes.io/proxy-send-timeout: "3600" name: emqxspec: rules:-host: emqx.cn.iotdp.cn http: paths:-backend: serviceName: my-emqx servicePort: 18083 path : /-backend: serviceName: my-emqx servicePort: 8083 path: / mqtt

Routing rules:

Match / mqtt routing to 8083 Websocket port

The rest of the paths are routed to 18083 dashboard

Deploy resources

$kubectl apply-f ingress.ymal-n my-emqx

After the deployment is completed, modify the DNS resolution, and you can access the dashboard through: http://emqx.cn.iotdp.cn

Then access Websocket through 8083 and / path

TCP

Ingress does not support TCP and UDP services, so Ingress uses-- tcp-services-configmap and-- udp-services-configmap to point to a configmap that contains a port mapping relationship. Key is an externally exposed port. The value format is:: [PROXY]: [PROXY]

Modify ingress-nginx deployment first

$kubectl edit deployment nginx-ingress-controller-n kube-system

Add the following to spec.template.spec.containers.args

-- tcp-services-configmap=$ (POD_NAMESPACE) / tcp-services

-- udp-services-configmap=$ (POD_NAMESPACE) / udp-services

Containers:-args:-/ nginx-ingress-controller -'- configmap=$ (POD_NAMESPACE) / nginx-configuration' -'- annotations-prefix=nginx.ingress.kubernetes.io' -'- publish-service=$ (POD_NAMESPACE) / nginx-ingress-lb' -'- tcp-services-configmap=$ (POD_NAMESPACE) / tcp-services' -'- udp-services-configmap=$ (POD_NAMESPACE) / udp-services'

Configure tcp-service

# tcp-service.yamlapiVersion: v1kind: ConfigMapmetadata: name: tcp-services namespace: ingress-nginxdata: 1883: "my-emqx/my-emqx:1883"

Finally, configure the corresponding port in the service

$kubectl edit svc nginx-ingress-lb-n kube-system

The configuration is as follows

ApiVersion: v1kind: Servicemetadata: labels: app: nginx-ingress-lb name: nginx-ingress-lb namespace: kube-systemspec: type: LoadBalancer ports:-name: http port: 80 protocol: TCP targetPort: 80-name: https port: 443 protocol: TCP targetPort: 443-name: emqx-tcp port: 1883 protocol: TCP targetPort: 1883 selector: app: ingress-nginx

View ingress-nginx services

$kubectl get svc nginx-ingress-lb-n kube-systemNAME TYPE CLUSTER-IP EXTERNAL-IP PORT (S) AGEnginx-ingress-lb ClusterIP 172.21.11.90 80:30639/TCP 443:30396/TCP,1883:30657/TCP 13m

We can connect to the EMQ X service through port 1883.

At this point, the study on "how to access EMQ X in the Kubernetes cluster" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report