【云原生 | Kubernetes 系列】—K8S部署RocketMQ集群(双主双从+同步模式)

【云原生 | Kubernetes 系列】—K8S部署RocketMQ集群(双主双从+同步模式)

版权 本文为云录原创文章,转载无需和我联系,但请注明来自云录 https://www.yunzhuan.site

rocketMQ高可用有很多种方式,比如:单机部署,多主集群,双主双从同步部署,双主双从异步部署,以及多主多从部署。部署集群可按照自己公司的实际情况进行部署。

单机部署:只启动一个rocketMQ实例就可以了,一般常用来本机测试使用。原因:一旦rocketMQ因某些原因挂掉,导致mq无法使用,则我们服务器无法接受信息与消费信息等。

多主集群:只部署mq主节点,无部署从节点。优点:配置简单,单个Master宕机或重启维护对应用无影响,即使机器宕机不可恢复情况下,也有其他主节点进行写入操作,

消息也不会丢(异步刷盘丢失少量消息,同步刷盘一条不丢),性能最高;

双主双从同步:部署四个节点,每个主节点都有一个从节点,主与从节点的信息通过同步的方式进行保存。优点:消息不会丢失,即:主节点挂了后,从节点的消息也不会造成丢失,只不过没法接受新消息,只能消费,但是能保证我消费的消息一定是准确的。缺点:客户端接受服务器响应时间长。可用于消息安全高的场景。

双主双从异步:与双主双从一致,只不过在主从数据传输是通过异步的方式,优点:客户端能快速的接收到服务器的消息,缺点:主节点挂的情况,从节点会丢失一部分消息。可用于允许消息丢失,吞吐量高的情景。

🍇 创建存储

这里我用ceph,需要自己准备存储

🍇 需要准备的材料 自行下载

apache-maven-3.6.3-bin.tar.gz

rocketmq-all-4.9.4-bin-release.zip

rocketmq-dashboard-master.zip

yarn-v1.22.10.tar.gz https://github.com/yarnpkg/yarn/releases/download/v1.22.10/yarn-v1.22.10.tar.gz

🍋 创建RocketMQ集群(双主双从同步模式)

制作rocketmq镜像

[root rocketmqimage]# ll
total 32200
-rw-r--r--. 1 root   root        319 May 15 13:38 Dockerfile
drwxr-xr-x. 6 root   root        103 May 15 13:37 rocketmq-all-4.9.4-bin-release
-rw-rw-r--. 1 root root 32967749 May 15 13:31 rocketmq-all-4.9.4-bin-release.zip

1:解压rocketmq-all-4.9.4-bin-release.zip 将runbroker.sh脚本文件里的内存设置调整小点

unzip  rocketmq-all-4.9.4-bin-release.zip
vim rocketmq-all-4.9.4-bin-release/bin/runbroker.sh
JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g"

2:准备dockerfile

FROM openjdk:8
RUN rm -f /etc/localtime \
&& ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone
ENV LANG en_US.UTF-8
COPY rocketmq-all-4.9.4-bin-release  /usr/local/rocketmq-all-4.9.4-bin-release
RUN  mkdir -p /data/rocketmq/store
CMD ["/bin/bash"]

3:制作镜像并上传到Harbor仓库

docker build -t 127.0.0.1/rocketmq/rocketmq-4.9.3:1.0 .
docker push  127.0.0.1/rocketmq/rocketmq-4.9.3:1.0

制作nameserver的image镜像

将上面rocketmq_image目录下的包rocketmq-all-4.9.4-bin-release 拷贝过来

[root nameserver_image]# ll
total 8
-rw-r--r-- 1 root root 525 Aug 23  2022 Dockerfile
-rw-r--r-- 1 root root  17 Aug 23  2022 namesrv.properties
drwxr-xr-x 6 root root 103 May 15 13:56 rocketmq-all-4.9.4-bin-release

1:准备 namesrv.properties 自定义nameserver的端口号

[root nameserver_image]# cat namesrv.properties 
listenPort=20801

2:准备dockerfile

[root nameserver_image]# cat Dockerfile 
FROM openjdk:8
RUN rm -f /etc/localtime \
&& ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone
ENV LANG en_US.UTF-8
COPY rocketmq-all-4.9.4-bin-release  /usr/local/rocketmq-all-4.9.4-bin-release
COPY namesrv.properties /usr/local/rocketmq-all-4.9.4-bin-release/conf/
WORKDIR /usr/local/rocketmq-all-4.9.4-bin-release
CMD ["/usr/local/rocketmq-all-4.9.4-bin-release/bin/mqnamesrv","-c","/usr/local/rocketmq-all-4.9.4-bin-release/conf/namesrv.properties"]

3: 制作镜像并上传到Harbor仓库

docker build -t 127.0.0.1/rocketmq/rocketmq_namesrv:4.9.3.1 .
docker push  127.0.0.1/rocketmq/rocketmq_namesrv:4.9.3.1

制作rocketmq的web可视化界面的image镜像

[root rockermq_web]# ll
total 14320
drwxr-xr-x 6 root   root        99 Aug 23  2022 apache-maven-3.6.3
-rw-rw-r-- 1 dotnet dotnet 9506321 Aug 23  2022 apache-maven-3.6.3-bin.tar.gz
-rw-r--r-- 1 root   root       674 May 15 15:26 Dockerfile
drwxr-xr-x 7 root   root       213 Apr 11  2022 rocketmq-dashboard-master
-rw-rw-r-- 1 dotnet dotnet 3906355 Aug 23  2022 rocketmq-dashboard-master.zip
-rw-rw-r-- 1 dotnet dotnet 1244965 May 15 15:21 yarn-v1.22.10.tar.gz

1:下载rocketmq-dashboard-master.zip和apache-maven-3.6.3-bin.tar.gz 并解压 2:修改 dashboard配置

vim rocketmq-dashboard-master/src/main/resources/application.yml
修改内容:
namesrvAddrs:
      - mq-namesrv.romq.svc.cluster.local:20801
loginRequired: true 
accessKey: rocketmq2  
secretKey: 12345678   
server:
  port: 8080
  servlet:
    encoding:
      charset: UTF-8
      enabled: true
      force: true
## SSL setting
#  ssl:
#    key-store: classpath:rmqcngkeystore.jks
#    key-store-password: rocketmq
#    key-store-type: PKCS12
#    key-alias: rmqcngkey

spring:
  application:
    name: rocketmq-dashboard

logging:
  config: classpath:logback.xml

rocketmq:
  config:
    # if this value is empty,use env value rocketmq.config.namesrvAddr  NAMESRV_ADDR | now, default localhost:9876
    # configure multiple namesrv addresses to manage multiple different clusters
    namesrvAddrs:
      - mq-namesrv.romq.svc.cluster.local:20801
    # if you use rocketmq version < 3.5.8, rocketmq.config.isVIPChannel should be false.default true
    isVIPChannel: false
    # timeout for mqadminExt, default 5000ms
    timeoutMillis:
    # rocketmq-console's data path:dashboard/monitor
    dataPath: /tmp/rocketmq-console/data
    # set it false if you don't want use dashboard.default true
    enableDashBoardCollect: true
    # set the message track trace topic if you don't want use the default one
    msgTrackTopicName:
    ticketKey: ticket
    # must create userInfo file: ${rocketmq.config.dataPath}/users.properties if the login is required
    loginRequired: true
    useTLS: false
    # set the accessKey and secretKey if you used acl设置acl权限
    accessKey: rocketmq2  # if version > 4.4.0 
    secretKey: 12345678   # if version > 4.4.0

threadpool:
  config:
    coreSize: 10
    maxSize: 10
    keepAliveTime: 3000
    queueSize: 5000

3:准备dockerfile

[root rockermq_web]# cat Dockerfile 
FROM openjdk:8
RUN rm -f /etc/localtime \
&& ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone
ENV LANG en_US.UTF-8
ENV MAVEN_HOME /usr/local/maven
ENV PATH $PATH:$MAVEN_HOME/bin
COPY rocketmq-dashboard-master   /usr/local/rocketmq-dashboard-master
COPY yarn-v1.22.10.tar.gz       /root/.m2/repository/com/github/eirslett/yarn/1.22.10/
COPY apache-maven-3.6.3 /usr/local/maven
WORKDIR /usr/local/rocketmq-dashboard-master
RUN mvn clean package -Dmaven.test.skip=true
WORKDIR /usr/local/rocketmq-dashboard-master/target
EXPOSE 8080
CMD ["nohup","java","-jar","rocketmq-dashboard-1.0.1-SNAPSHOT.jar","&"]

4:制作镜像并上传到Harbor仓库

docker build -t 127.0.0.1/rocketmq/rocketmq-dashboard:v4.9.3.1 .
docker push     127.0.0.1/rocketmq/rocketmq-dashboard:v4.9.3.1

准备配置文件 configmap

1:我的broker配置文件

[root config]# ll
total 16
-rw-rw-r--. 1 dotnet dotnet 638 May 15 15:53 broker-a.properties
-rw-rw-r--. 1 dotnet dotnet 630 May 15 15:53 broker-a-s.properties
-rw-rw-r--. 1 dotnet dotnet 636 May 15 15:53 broker-b.properties
-rw-rw-r--. 1 dotnet dotnet 632 May 15 15:53 broker-b-s.properties
[root config]# cat broker-a.properties 
brokerClusterName=rocketmq-cluster
brokerName=broker-a
brokerId=0
namesrvAddr=mq-namesrv.romq.svc.cluster.local:20801
defaultTopicQueueNums=4
autoCreateTopicEnable=false
autoCreateSubscriptionGroup=true
brokerIP1=公网ip或是负载ip
listenPort=30811
deleteWhen=04
fileReservedTime=48
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
diskMaxUsedSpaceRatio=88
storePathRootDir=/data/rocketmq/store
maxMessageSize=65536
#Broker 的角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole=SYNC_MASTER
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=SYNC_FLUSH
aclEnable=true
[root config]# cat broker-a-s.properties 
brokerClusterName=rocketmq-cluster
brokerName=broker-a
brokerId=1
namesrvAddr=mq-namesrv.romq.svc.cluster.local:20801
defaultTopicQueueNums=4
autoCreateTopicEnable=false
autoCreateSubscriptionGroup=true
brokerIP1=公网ip或是负载ip
listenPort=30812
deleteWhen=04
fileReservedTime=48
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
diskMaxUsedSpaceRatio=88
storePathRootDir=/data/rocketmq/store
maxMessageSize=65536
brokerRole=SLAVE
flushDiskType=SYNC_FLUSH
aclEnable=true
[root config]# cat broker-b.properties 
brokerClusterName=rocketmq-cluster
brokerName=broker-b
brokerId=0
namesrvAddr=mq-namesrv.romq.svc.cluster.local:20801
defaultTopicQueueNums=4
autoCreateTopicEnable=false
autoCreateSubscriptionGroup=true
brokerIP1=公网ip或是负载ip
listenPort=30813
deleteWhen=04
fileReservedTime=48
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
diskMaxUsedSpaceRatio=88
storePathRootDir=/data/rocketmq/store
maxMessageSize=65536
brokerRole=SYNC_MASTER
flushDiskType=SYNC_FLUSH
aclEnable=true
[root config]# cat broker-b-s.properties 
brokerClusterName = rocketmq-cluster
brokerName=broker-b
brokerId=1
namesrvAddr=mq-namesrv.romq.svc.cluster.local:20801
defaultTopicQueueNums=4
autoCreateTopicEnable=false
autoCreateSubscriptionGroup=true
brokerIP1=公网ip或是负载ip
listenPort=30814
deleteWhen=04
fileReservedTime=48
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
diskMaxUsedSpaceRatio=88
storePathRootDir=/data/rocketmq/store
maxMessageSize=65536
brokerRole=SLAVE
flushDiskType=SYNC_FLUSH
aclEnable=true

2:创建CM

kubectl create configmap rocketmq-config --from-file=broker-a.properties --from-file=broker-b.properties --from-file=broker-a-s.properties --from-file=broker-b-s.properties -n romq

准备Deploy

1:我的deploy

[root rocketmqDeploy]# ll
total 24
-rw-rw-r--. 1 dotnet dotnet 2908 May 15 16:50 broker-a-deployment.yaml
-rw-rw-r--. 1 dotnet dotnet 3041 May 15 16:50 broker-a-s-deployment.yaml
-rw-rw-r--. 1 dotnet dotnet 2908 May 15 16:50 broker-b-deployment.yaml
-rw-rw-r--. 1 dotnet dotnet 3041 May 15 16:50 broker-b-s-deployment.yaml
-rw-rw-r--. 1 dotnet dotnet 1811 May 15 15:50 namesrv-deployment.yaml
-rw-rw-r--. 1 dotnet dotnet 1735 May 15 17:27 rocketmq-externals-deployment.yaml
[root rocketmqDeploy]# cat broker-a-deployment.yaml 
apiVersion: v1
kind: Service
metadata:
  labels:
    app: broker-a
  name: broker-a
spec:
  type: NodePort
  ports:
    - port: 30811
      targetPort: 30811
      name: broker-port
      nodePort: 30811
  selector:
    app: broker-a
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: broker-a
spec:
  serviceName: broker-a
  replicas: 1
  selector:
    matchLabels:
      app: broker-a
  template:
    metadata:
      labels:
        app: broker-a
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: "app"
                    operator: In
                    values:
                      - broker-a
              topologyKey: "kubernetes.io/hostname"
      containers:
        - name: broker-a
          image: 127.0.0.1/rocketmq/rocketmq-4.9.3:1.0
          imagePullPolicy: Always
          command: ["sh","-c","/usr/local/rocketmq-all-4.9.4-bin-release/bin/mqbroker  -c /usr/local/rocketmq-all-4.9.4-bin-release/conf/broker-a.properties"]
          volumeMounts:
            - mountPath: /root/logs
              name: rocketmq-data-cluster
              subPath: mq-brokeroptlogs
            - mountPath: /data/rocketmq
              name: rocketmq-data-cluster
              subPath: mq-brokeroptstore
            - name: broker-config
              mountPath: /usr/local/rocketmq-all-4.9.4-bin-release/conf/broker-a.properties
              subPath: broker-a.properties
            - name: time
              mountPath: /etc/localtime
          env:
            - name: JAVA_OPT_EXT
              value: '-Xmx4096m -Xms4096m -Xmn1048m'
          resources:
            requests:
              memory: 2024Mi
              cpu: 1024m
            limits:
              memory: 6024Mi
              cpu: 6000m
          lifecycle:
            postStart:
              exec:
                command: ["/bin/sh","-c","touch /tmp/health"]
          livenessProbe:
            exec:
              command: ["test","-e","/tmp/health"]
            initialDelaySeconds: 5
            timeoutSeconds: 5
            periodSeconds: 10
          readinessProbe:
            tcpSocket:
              port: 30811
            initialDelaySeconds: 15
            timeoutSeconds: 5
            periodSeconds: 20
      volumes:
        - name: broker-config
          configMap:
            name: rocketmq-config
        - name: time
          hostPath:
            path: /usr/share/zoneinfo/Asia/Shanghai
  volumeClaimTemplates:
    - metadata:
        name: rocketmq-data-cluster
      spec:
        storageClassName: rook-ceph-block
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 20Gi
[root rocketmqDeploy]# cat broker-a-s-deployment.yaml 
apiVersion: v1
kind: Service
metadata:
  labels:
    app: broker-a-s
  name: broker-a-s
spec:
  type: NodePort
  ports:
    - port: 30812
      targetPort: 30812
      name: broker-port
      nodePort: 30812
  selector:
    app: broker-a-s
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: broker-a-s
spec:
  serviceName: broker-a-s
  replicas: 1
  selector:
    matchLabels:
      app: broker-a-s
  template:
    metadata:
      labels:
        app: broker-a-s
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: "app"
                    operator: In
                    values:
                      - broker-a-s
              topologyKey: "kubernetes.io/hostname"
      containers:
        - name: broker-a-s
          image: 127.0.0.1/rocketmq/rocketmq-4.9.3:1.0
          imagePullPolicy: Always
          command: ["sh","-c","/usr/local/rocketmq-all-4.9.4-bin-release/bin/mqbroker  -c /usr/local/rocketmq-all-4.9.4-bin-release/conf/broker-a-s.properties"]
          volumeMounts:
            - mountPath: /root/logs
              name: rocketmq-data-cluster
              subPath: mq-brokeroptlogs
            - mountPath: /data/rocketmq
              name: rocketmq-data-cluster
              subPath: mq-brokeroptstore
            - name: broker-config
              mountPath: /usr/local/rocketmq-all-4.9.4-bin-release/conf/broker-a-s.properties
              subPath: broker-a-s.properties
            - name: time
              mountPath: /etc/localtime
          env:
            - name: JAVA_OPT_EXT
              value: '-Xmx4096m -Xms4096m -Xmn1048m'
          resources:
            requests:
              memory: 2024Mi
              cpu: 1024m
            limits:
              memory: 6024Mi
              cpu: 6000m
          lifecycle:
            postStart:
              exec:
                command: ["/bin/sh","-c","touch /tmp/health"]
          livenessProbe:
            exec:
              command: ["test","-e","/tmp/health"]
            initialDelaySeconds: 5
            timeoutSeconds: 5
            periodSeconds: 10
          readinessProbe:
            tcpSocket:
              port: 30812
            initialDelaySeconds: 15
            timeoutSeconds: 5
            periodSeconds: 20
      volumes:
        - name: broker-config
          configMap:
            name: rocketmq-config
            items:
              - key: broker-a-s.properties
                path: broker-a-s.properties
        - name: time
          hostPath:
            path: /usr/share/zoneinfo/Asia/Shanghai
  volumeClaimTemplates:
    - metadata:
        name: rocketmq-data-cluster
      spec:
        storageClassName: rook-ceph-block
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 20Gi
[root rocketmqDeploy]# cat broker-b-deployment.yaml 
apiVersion: v1
kind: Service
metadata:
  labels:
    app: broker-b
  name: broker-b
spec:
  type: NodePort
  ports:
    - port: 30813
      targetPort: 30813
      name: broker-port
      nodePort: 30813
  selector:
    app: broker-b
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: broker-b
spec:
  serviceName: broker-b
  replicas: 1
  selector:
    matchLabels:
      app: broker-b
  template:
    metadata:
      labels:
        app: broker-b
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: "app"
                    operator: In
                    values:
                      - broker-b
              topologyKey: "kubernetes.io/hostname"
      containers:
        - name: broker-b
          image: 127.0.0.1/rocketmq/rocketmq-4.9.3:1.0
          imagePullPolicy: Always
          command: ["sh","-c","/usr/local/rocketmq-all-4.9.4-bin-release/bin/mqbroker  -c /usr/local/rocketmq-all-4.9.4-bin-release/conf/broker-b.properties"]
          volumeMounts:
            - mountPath: /root/logs
              name: rocketmq-data-cluster
              subPath: mq-brokeroptlogs
            - mountPath: /data/rocketmq
              name: rocketmq-data-cluster
              subPath: mq-brokeroptstore
            - name: broker-config
              mountPath: /usr/local/rocketmq-all-4.9.4-bin-release/conf/broker-b.properties
              subPath: broker-b.properties
            - name: time
              mountPath: /etc/localtime
          lifecycle:
            postStart:
              exec:
                command: ["/bin/sh","-c","touch /tmp/health"]
          livenessProbe:
            exec:
              command: ["test","-e","/tmp/health"]
            initialDelaySeconds: 5
            timeoutSeconds: 5
            periodSeconds: 10
          readinessProbe:
            tcpSocket:
              port: 30813
            initialDelaySeconds: 15
            timeoutSeconds: 5
            periodSeconds: 20
          env:
            - name: JAVA_OPT_EXT
              value: '-Xmx4096m -Xms4096m -Xmn1048m'
          resources:
            requests:
              memory: 2024Mi
              cpu: 1024m
            limits:
              memory: 6024Mi
              cpu: 6000m
      volumes:
        - name: broker-config
          configMap:
            name: rocketmq-config
        - name: time
          hostPath:
            path: /usr/share/zoneinfo/Asia/Shanghai
  volumeClaimTemplates:
    - metadata:
        name: rocketmq-data-cluster
      spec:
        storageClassName: rook-ceph-block
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 20Gi
[root rocketmqDeploy]# cat broker-b-s-deployment.yaml 
apiVersion: v1
kind: Service
metadata:
  labels:
    app: broker-b-s
  name: broker-b-s
spec:
  type: NodePort
  ports:
    - port: 30814
      targetPort: 30814
      name: broker-port
      nodePort: 30814
  selector:
    app: broker-b-s
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: broker-b-s
spec:
  serviceName: broker-b-s
  replicas: 1
  selector:
    matchLabels:
      app: broker-b-s
  template:
    metadata:
      labels:
        app: broker-b-s
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: "app"
                    operator: In
                    values:
                      - broker-b-s
              topologyKey: "kubernetes.io/hostname"
      containers:
        - name: broker-b-s
          image: 127.0.0.1/rocketmq/rocketmq-4.9.3:1.0
          imagePullPolicy: Always
          command: ["sh","-c","/usr/local/rocketmq-all-4.9.4-bin-release/bin/mqbroker  -c /usr/local/rocketmq-all-4.9.4-bin-release/conf/broker-b-s.properties"]
          volumeMounts:
            - mountPath: /root/logs
              name: rocketmq-data-cluster
              subPath: mq-brokeroptlogs
            - mountPath: /data/rocketmq
              name: rocketmq-data-cluster
              subPath: mq-brokeroptstore
            - name: broker-config
              mountPath: /usr/local/rocketmq-all-4.9.4-bin-release/conf/broker-b-s.properties
              subPath: broker-b-s.properties
            - name: time
              mountPath: /etc/localtime
          lifecycle:
            postStart:
              exec:
                command: ["/bin/sh","-c","touch /tmp/health"]
          livenessProbe:
            exec:
              command: ["test","-e","/tmp/health"]
            initialDelaySeconds: 5
            timeoutSeconds: 5
            periodSeconds: 10
          readinessProbe:
            tcpSocket:
              port: 30814
            initialDelaySeconds: 15
            timeoutSeconds: 5
            periodSeconds: 20
          env:
            - name: JAVA_OPT_EXT
              value: '-Xmx4096m -Xms4096m -Xmn1048m'
          resources:
            requests:
              memory: 2024Mi
              cpu: 1024m
            limits:
              memory: 6024Mi
              cpu: 6000m
      volumes:
        - name: broker-config
          configMap:
            name: rocketmq-config
            items:
              - key: broker-b-s.properties
                path: broker-b-s.properties
        - name: time
          hostPath:
            path: /usr/share/zoneinfo/Asia/Shanghai
  volumeClaimTemplates:
    - metadata:
        name: rocketmq-data-cluster
      spec:
        storageClassName: rook-ceph-block
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 20Gi
[root rocketmqDeploy]# cat namesrv-deployment.yaml 
apiVersion: v1
kind: Service
metadata:
  labels:
    app: mq-namesrv
  name: mq-namesrv
spec:
  type: NodePort
  ports:
    - port: 20801
      targetPort: 20801
      name: namesrv-port
      nodePort: 30815
  selector:
    app: mq-namesrv
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mq-namesrv
spec:
  serviceName: mq-namesrv
  replicas: 1
  selector:
    matchLabels:
      app: mq-namesrv
  template:
    metadata:
      labels:
        app: mq-namesrv
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: "app"
                    operator: In
                    values:
                      - mq-namesrv
              topologyKey: "kubernetes.io/hostname"
      containers:
        - name: mq-namesrv
          image: 127.0.0.1/rocketmq/rocketmq_namesrv:4.9.3.1
          imagePullPolicy: Always
          env:
            - name: JAVA_OPT_EXT
              value: '-Xmx2048m -Xms2048m -Xmn512m'
          resources:
            requests:
              memory: 2024Mi
              cpu: 1024m
            limits:
              memory: 4096Mi
              cpu: 3000m
          lifecycle:
            postStart:
              exec:
                command: ["/bin/sh","-c","touch /tmp/health"]
          livenessProbe:
            exec:
              command: ["test","-e","/tmp/health"]
            initialDelaySeconds: 5
            timeoutSeconds: 5
            periodSeconds: 10
          readinessProbe:
            tcpSocket:
              port: 20801
            initialDelaySeconds: 15
            timeoutSeconds: 5
            periodSeconds: 20
[root rocketmqDeploy]# cat rocketmq-externals-deployment.yaml 
apiVersion: v1
kind: Service
metadata:
  labels:
    app: mq-externals
  name: mq-externals
spec:
  type: NodePort
  ports:
    - port: 8080
      targetPort: 8080
      name: console-port
      nodePort: 30816
  selector:
    app: mq-externals
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mq-externals
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mq-externals
  template:
    metadata:
      labels:
        app: mq-externals
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: "app"
                    operator: In
                    values:
                      - mq-externals
              topologyKey: "kubernetes.io/hostname"
      containers:
        - name: mq-externals
          image: 127.0.0.1/rocketmq/rocketmq-dashboard:v4.9.3.1
          imagePullPolicy: Always
          lifecycle:
            postStart:
              exec:
                command: ["/bin/sh","-c","touch /tmp/health"]
          livenessProbe:
            exec:
              command: ["test","-e","/tmp/health"]
            initialDelaySeconds: 5
            timeoutSeconds: 5
            periodSeconds: 10
          readinessProbe:
            tcpSocket:
              port: 8080
            initialDelaySeconds: 15
          env:
            - name: JAVA_OPT_EXT
              value: '-Xmx1024m -Xms1024m -Xmn512m'
          resources:
            requests:
              memory: 1024Mi
              cpu: 1024m
            limits:
              memory: 4096Mi
              cpu: 3000m

2: 部署deploy

kubectl apply  -f ./  -n  romq
[root rocketmqDeploy]# kubectl  get po  -n  romq
NAME                           READY   STATUS    RESTARTS   AGE
broker-a-0                     1/1     Running   0          65m
broker-a-s-0                   1/1     Running   0          65m
broker-b-0                     1/1     Running   0          65m
broker-b-s-0                   1/1     Running   0          65m
mq-externals-6cfc5d9bc-w4cmp   1/1     Running   0          45s
mq-namesrv-0                   1/1     Running   0          65m
[root rocketmqDeploy]# kubectl  get svc  -n  romq
NAME           TYPE       CLUSTER-IP       EXTERNAL-IP   PORT(S)           AGE
broker-a       NodePort   10.99.180.11     <none>        30811:30811/TCP   67m
broker-a-s     NodePort   10.105.248.30    <none>        30812:30812/TCP   66m
broker-b       NodePort   10.102.87.207    <none>        30813:30813/TCP   66m
broker-b-s     NodePort   10.103.106.247   <none>        30814:30814/TCP   66m
mq-externals   NodePort   10.96.128.101    <none>        8080:30816/TCP    66m
mq-namesrv     NodePort   10.105.103.115   <none>        20801:30815/TCP   66m

3:访问dashboard: http://$NODE_IP:30816/

版权 本文为云录原创文章,转载无需和我联系,但请注明来自云录 https://www.yunzhuan.site

热门相关:惊世第一妃:魔帝,宠上身!   惊世第一妃:魔帝,宠上身!   陆鸣至尊神殿   凤逆天下:战神杀手妃   一个人的一往情深