分别部署rocketmqnamesrv、rocketmqbroker、rocketmq-dashboard三个。
1、部署rocketmqnamesrv
部署时,rocketmq的日志存储采用hostPath方式挂载到服务器磁盘上,所以需要指定node节点。
--- apiVersion: apps/v1 kind: Deployment metadata: labels: app: rocketmqnamesrv k8s.kuboard.cn/layer: cloud name: rocketmqnamesrv namespace: kube-public spec: selector: matchLabels: app: rocketmqnamesrv template: metadata: labels: app: rocketmqnamesrv spec: containers: - command: - sh - /home/rocketmq/rocketmq-5.1.2/bin/mqnamesrv env: - name: TZ value: Asia/Shanghai - name: JAVA_OPT_EXT value: '-Duser.home=/home/rocketmq -Xms512M -Xmx512M -Xmn128m' - name: autoCreateTopicEnable value: 'true' image: 'apache/rocketmq:5.1.2' imagePullPolicy: IfNotPresent name: rocketmqnamesrv volumeMounts: - mountPath: /root/logs name: srclogs - mountPath: /root/store name: srcstore volumes: - hostPath: path: /opt/rocketmq-server/logs type: DirectoryOrCreate name: srclogs - hostPath: path: /opt/rocketmq-server/store type: DirectoryOrCreate name: srcstore --- apiVersion: v1 kind: Service metadata: name: rocketmqnamesrv namespace: kube-public spec: ports: - name: namesrvport nodePort: 31376 port: 9876 protocol: TCP targetPort: 9876 selector: app: rocketmqnamesrv type: NodePort
2、部署rocketmqbroker
rocketmqbroker部署到K8s上,需要修改brocket的ip,默认是docket内ip,修改为K8s的服务器Ip。采用configmap方式将broker.conf文件挂载出来。
configmap.yaml如下,需要修改brokerIP1 的值为你服务器的Ip。
--- apiVersion: v1 data: config: |- brokerClusterName = DefaultCluster brokerName = broker-c brokerId = 0 deleteWhen = 04 fileReservedTime = 48 brokerRole = ASYNC_MASTER flushDiskType = ASYNC_FLUSH brokerIP1 = 192.168.111.90 kind: ConfigMap metadata: name: roketmqconfig namespace: kube-public
rocketmqbroker部署的yaml文件如下:
--- apiVersion: apps/v1 kind: Deployment metadata: labels: app: rocketmqbroker k8s.kuboard.cn/layer: cloud name: rocketmqbroker namespace: kube-public spec: selector: matchLabels: app: rocketmqbroker template: metadata: labels: app: rocketmqbroker spec: containers: - command: - sh - /home/rocketmq/rocketmq-5.1.2/bin/mqbroker - '-n' - 'rocketmqnamesrv:9876' - '-c' - /home/rocketmq/rocketmq-5.1.2/conf/broker.conf env: - name: TZ value: Asia/Shanghai - name: JAVA_OPT_EXT value: '-Xms512M -Xmx512M -Xmn128m' - name: NAMESRV_ADDR value: 'rocketmqnamesrv:9876' image: 'apache/rocketmq:5.1.2' imagePullPolicy: IfNotPresent name: rocketmqbroker volumeMounts: - mountPath: /home/rocketmq/rocketmq-5.1.2/conf/broker.conf name: rocketmqconfig subPath: broker.conf - mountPath: /root/logs name: logsconfig - mountPath: /root/store name: storeconfig nodeName: node3 restartPolicy: Always volumes: - configMap: defaultMode: 420 items: - key: config path: broker.conf name: roketmqconfig name: rocketmqconfig - hostPath: path: /opt/rocketmq-broker/logs type: DirectoryOrCreate name: logsconfig - hostPath: path: /opt/rocketmq-broker/store type: DirectoryOrCreate name: storeconfig --- apiVersion: v1 kind: Service metadata: labels: app: rocketmqbroker name: rocketmqbroker namespace: kube-public spec: ports: - name: broker-port nodePort: 10911 port: 10911 protocol: TCP targetPort: 10911 - name: 7cpk4a nodePort: 10912 port: 10912 protocol: TCP targetPort: 10912 - name: ykdmnd nodePort: 10909 port: 10909 protocol: TCP targetPort: 10909 selector: app: rocketmqbroker sessionAffinity: None type: NodePort
3、部署rocketmq-dashboard
--- apiVersion: apps/v1 kind: Deployment metadata: labels: app: rocketmq-dashboard name: rocketmq-dashboard namespace: kube-public spec: selector: matchLabels: app: rocketmq-dashboard template: metadata: labels: app: rocketmq-dashboard spec: containers: - env: - name: TZ value: Asia/Shanghai - name: JAVA_OPTS value: >- -Drocketmq.namesrv.addr=rocketmqnamesrv:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false image: apacherocketmq/rocketmq-dashboard imagePullPolicy: IfNotPresent name: rocketmq-dashboard tcpSocket: port: 8080 dnsPolicy: ClusterFirst restartPolicy: Always --- apiVersion: v1 kind: Service metadata: annotations: k8s.kuboard.cn/workload: rocketmq-dashboard labels: app: rocketmq-dashboard name: rocketmq-dashboard namespace: kube-public spec: ports: - name: port nodePort: 20880 port: 8080 protocol: TCP targetPort: 8080 selector: app: rocketmq-dashboard type: NodePort
部署完成后,浏览器访问:http://ip:20880就可以查看dashboard了。
遇到的问题:
之前部署的时候,rocketmqbroker采用nodeport方式暴露出来的节点端口不是10911等服务端口,导致dashboard一直提示连接失败。将nodeprot节点端口与服务端口设置为一致即可。
k8s的nodeport使用的默认端口范围是30000-32767。若想设置10911端口,需要修改默认端口范围。
标签:name,部署,app,rocketmqnamesrv,rocketmqbroker,dashboard,k8s,rocketmq From: https://www.cnblogs.com/nuomm/p/17652344.html