kubernetes 部署 rocketmq 集群

以下所用到的文件皆在: https://gitee.com/glnp/docker-case.git

介绍

详细介绍查看rocketmq 介绍和容器部署

本案例部署的是RocketMQ的"双主双从+同步模式",涉及6个pod:

  • broker-a 主1
  • broker-b 主2
  • broker-a-s 从1
  • broker-a-s 从2
  • NameServer(注册中心)
  • rocketmq-externals(可视化web界面)

部署过程记录

准备nfs-client-provisioner

编写脚本安装nfs

#! /usr/bin/env python3
import platform
import os
import stat

def init_nfs():
    '''
    :param nfs_str: nfs 中共享挂载路径参数
    '''
    nfs_str="/data/nfs   *(rw,sync,no_root_squash,no_subtree_check)"
    with open('/etc/exports','w',encoding='utf8') as n:
        n.write(nfs_str)

    if not os.path.exists('/data/nfs'):
        '''
        :param exisk_ok: 如果为真执行 -p 操作
        '''
        os.makedirs('/data/nfs',exist_ok=True)    # 如果指定的路径不存在,新建

    # 授权,相当于执行 --> chmod 777 /data/nfs
    os.chmod('/data/nfs',stat.S_IRWXU+stat.S_IRWXG+stat.S_IRWXO)

def main():
    '''
    :param system_type: 操作系统类型 例: ubuntu | centos 
    '''
    system_type=platform.uname().version.lower()
    if 'ubuntu' in system_type:
        #安装nfs
        os.system('apt install -y nfs-kernel-server rpcbind')
        init_nfs()
        # 启动&开机自启
        os.system('systemctl start rpcbind && systemctl start nfs-kernel-server.service')
        #如果未启动成功,请手动执行: /etc/init.d/nfs-kernel-server restart
        os.system('systemctl enable rpcbind && systemctl enable nfs-kernel-server.service')
    elif 'centos' in system_type:
        #安装nfs
        os.system('yum install -y nfs-utils rpcbind')
        init_nfs()
        # 启动&开机自启
        os.system('systemctl start rpcbind && systemctl start nfs-server')
        os.system('systemctl enable rpcbind && systemctl enable nfs-server')

if __name__=='__main__':
    main()

安装

python3 init_nfs.py

创建 rbac

---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: nfs-provisioner
  namespace: default
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
   name: nfs-provisioner-runner
   namespace: default
rules:
   -  apiGroups: [""]
      resources: ["persistentvolumes"]
      verbs: ["get", "list", "watch", "create", "delete"]
   -  apiGroups: [""]
      resources: ["persistentvolumeclaims"]
      verbs: ["get", "list", "watch", "update"]
   -  apiGroups: ["storage.k8s.io"]
      resources: ["storageclasses"]
      verbs: ["get", "list", "watch"]
   -  apiGroups: [""]
      resources: ["events"]
      verbs: ["watch", "create", "update", "patch"]
   -  apiGroups: [""]
      resources: ["services", "endpoints"]
      verbs: ["get","create","list", "watch","update"]
   -  apiGroups: ["extensions"]
      resources: ["podsecuritypolicies"]
      resourceNames: ["nfs-provisioner"]
      verbs: ["use"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: run-nfs-provisioner
subjects:
  - kind: ServiceAccount
    name: nfs-provisioner
    namespace: default
roleRef:
  kind: ClusterRole
  name: nfs-provisioner-runner
  apiGroup: rbac.authorization.k8s.io

部署,查看

kubetcl nfs-rbac.yaml
#查看
kubectl get sa
NAME              SECRETS   AGE
default           1         37d
nfs-provisioner   1         19s

创建storageclass

---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: nfs-storage
  namespace: default
  annotations:
    storageclass.kubernetes.io/is-default-class: "false"  ## 是否设置为默认的storageclass
provisioner: nfs-client                                   ## 动态卷分配者名称,必须和上面创建的"provisioner"变量中设置的Name一致
reclaimPolicy: Retain                                     ## 指定回收政策,storage 默认为 Delete

部署,查看

kubectl apply  -f  nfs-storageclass.yaml 
#查看
kubectl get sc
NAME                   PROVISIONER             RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
local-path (default)   rancher.io/local-path   Delete          WaitForFirstConsumer   false                  37d
nfs-storage            nfs-client              Retain          Immediate              false                  14s

创建nfs-client-provisioner

项目仓库地址: https://github.com/kubernetes-sigs/nfs-subdir-external-provisioner

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nfs-client-provisioner
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nfs-client-provisioner
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: nfs-client-provisioner
    spec:
      serviceAccount: nfs-provisioner
      containers:
        - name: nfs-client-provisioner
          #image: gcr.io/k8s-staging-sig-storage/nfs-subdir-external-provisioner:v4.0.0
          image: registry.cn-beijing.aliyuncs.com/mydlq/nfs-subdir-external-provisioner:v4.0.0
          imagePullPolicy: IfNotPresent
          volumeMounts:
            - name: nfs-client-root
              mountPath:  /persistentvolumes
          env:
            - name: PROVISIONER_NAME
              value: nfs-client
            - name: NFS_SERVER
              value: 192.168.50.134
            - name: NFS_PATH
              value: /data/nfs
      volumes:
        - name: nfs-client-root
          nfs:
            server: 192.168.50.134
            path: /data/nfs

部署,查看

kubectl apply -f  nfs-provisioner.yaml 
deployment.apps/nfs-client-provisioner created
#查看
kubectl get pods
NAME                                      READY   STATUS              RESTARTS   AGE
nfs-client-provisioner-55d4f9ff67-688zr   0/1     ContainerCreating   0          5s

准备conf 配置文件

注意:
#是否允许broker自动创建topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许broker自动创建订阅组,建议线下开始,线上关闭
autoCreateSubscriptionGroup=true

broker-a.yaml

---
apiVersion: v1
data:
  broker.conf: |-
    brokerClusterName=DefaultCluster
    brokerName=broker-a
    brokerId=0
    namesrvAddr=mq-ns.default.svc.cluster.local:9876
    defaultTopicQueueNums=4
    #Whether to allow the broker to automatically create topics, it is recommended to open offline and close online
    autoCreateTopicEnable=true
    #Whether to allow the broker to automatically create a subscription group, it is recommended to start offline and close online
    autoCreateSubscriptionGroup=true
    listenPort=10911
    deleteWhen=04
    fileReservedTime=120
    mapedFileSizeCommitLog=1073741824
    mapedFileSizeConsumeQueue=300000
    destroyMapedFileInterval=120000
    redeleteHangedFileInterval=120000
    diskMaxUsedSpaceRatio=88
    maxMessageSize=65536
    flushCommitLogLeastPages=4
    flushConsumeQueueLeastPages=2
    flushCommitLogThoroughInterval=10000
    flushConsumeQueueThoroughInterval=60000
    checkTransactionMessageEnable=false
    sendMessageThreadPoolNums=16
    pullMessageThreadPoolNums=16
    brokerRole=ASYNC_MASTER
    flushDiskType=ASYNC_FLUSH
kind: ConfigMap
metadata:
  creationTimestamp: null
  name: broker-a
  namespace: default

broker-a-s.yaml

---
apiVersion: v1
data:
  broker.conf: |-
    brokerClusterName=DefaultCluster
    brokerName=broker-a
    brokerId=1
    namesrvAddr=mq-ns.default.svc.cluster.local:9876
    defaultTopicQueueNums=4
    autoCreateTopicEnable=true
    autoCreateSubscriptionGroup=true
    listenPort=10911
    deleteWhen=04
    fileReservedTime=120
    mapedFileSizeCommitLog=1073741824
    mapedFileSizeConsumeQueue=300000
    destroyMapedFileInterval=120000
    redeleteHangedFileInterval=120000
    diskMaxUsedSpaceRatio=88
    maxMessageSize=65536
    flushCommitLogLeastPages=4
    flushConsumeQueueLeastPages=2
    flushCommitLogThoroughInterval=10000
    flushConsumeQueueThoroughInterval=60000
    checkTransactionMessageEnable=false
    sendMessageThreadPoolNums=16
    pullMessageThreadPoolNums=16
    brokerRole=SLAVE
    flushDiskType=ASYNC_FLUSH
kind: ConfigMap
metadata:
  creationTimestamp: null
  name: broker-a-s
  namespace: default

broker-b.yaml

---
apiVersion: v1
data:
  broker.conf: |-
    brokerClusterName=DefaultCluster
    brokerName=broker-b
    brokerId=0
    namesrvAddr=mq-ns.default.svc.cluster.local:9876
    defaultTopicQueueNums=4
    autoCreateTopicEnable=true
    autoCreateSubscriptionGroup=true
    listenPort=10911
    deleteWhen=04
    fileReservedTime=120
    mapedFileSizeCommitLog=1073741824
    mapedFileSizeConsumeQueue=300000
    destroyMapedFileInterval=120000
    redeleteHangedFileInterval=120000
    diskMaxUsedSpaceRatio=88
    maxMessageSize=65536
    flushCommitLogLeastPages=4
    flushConsumeQueueLeastPages=2
    flushCommitLogThoroughInterval=10000
    flushConsumeQueueThoroughInterval=60000
    checkTransactionMessageEnable=false
    sendMessageThreadPoolNums=16
    pullMessageThreadPoolNums=16
    brokerRole=ASYNC_MASTER
    flushDiskType=ASYNC_FLUSH
kind: ConfigMap
metadata:
  creationTimestamp: null
  name: broker-b
  namespace: default

broker-b-s.yaml

---
apiVersion: v1
data:
  broker.conf: |-
    brokerClusterName=DefaultCluster
    brokerName=broker-b
    brokerId=1
    namesrvAddr=mq-ns.default.svc.cluster.local:9876
    defaultTopicQueueNums=4
    autoCreateTopicEnable=true
    autoCreateSubscriptionGroup=true
    listenPort=10911
    deleteWhen=04
    fileReservedTime=120
    mapedFileSizeCommitLog=1073741824
    mapedFileSizeConsumeQueue=300000
    destroyMapedFileInterval=120000
    redeleteHangedFileInterval=120000
    diskMaxUsedSpaceRatio=88
    maxMessageSize=65536
    flushCommitLogLeastPages=4
    flushConsumeQueueLeastPages=2
    flushCommitLogThoroughInterval=10000
    flushConsumeQueueThoroughInterval=60000
    checkTransactionMessageEnable=false
    sendMessageThreadPoolNums=16
    pullMessageThreadPoolNums=16
    brokerRole=SLAVE
    flushDiskType=ASYNC_FLUSH
kind: ConfigMap
metadata:
  creationTimestamp: null
  name: broker-b-s
  namespace: default

启动所需的配置文件

conf
├── broker-a-s.yaml
├── broker-a.yaml
├── broker-b-s.yaml
└── broker-b.yaml
#启动
kubectl apply -f conf/
#查看
kubectl get configmaps 
NAME               DATA   AGE
broker-a-s         1      5s
broker-a           1      5s
broker-b-s         1      5s
broker-b           1      5s

部署 rocketmq 集群pod

broker-a-pods.yaml

apiVersion: v1
kind: Service
metadata:
  labels:
    app: broker-a
  name: broker-a
  namespace: default
spec:
  # type: NodePort
  type: ClusterIP
  ports:
  - port: 10911
    targetPort: 10911
    name: broker-port
  selector:
    app: broker-a
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: broker-a
  namespace: default
spec:
  serviceName: broker-a
  replicas: 1
  selector:
    matchLabels:
      app: broker-a
  template:
    metadata:
     labels:
       app: broker-a
    spec:
      # affinity:
      #   #podAntiAffinity 反亲合性
      #   podAntiAffinity:
      #     requiredDuringSchedulingIgnoredDuringExecution:
      #       - labelSelector:
      #           matchExpressions:
      #             - key: "app"
      #               operator: In
      #               values:
      #                 - broker-a
      #         topologyKey: "kubernetes.io/hostname"
      containers:
      - name: broker-a
        #image: foxiswho/rocketmq:4.8.0   #下面使用的是用官方地址自行构建的镜像,推荐直接使用这个
        image: apacherocketmq/rocketmq:4.8.0
        imagePullPolicy: IfNotPresent
        env:
          - name: TZ
            value: Asia/Shanghai
          - name: NAMESRV_ADDR
            value: "mq-ns.default.svc.cluster.local:9876"
          - name: JAVA_OPT_EXT
            value: "-Duser.home=/home/rocketmq -Xms512M -Xmx512M -Xmn128m"
        command: ["sh","-c","mqbroker -c /home/broker.conf"]
        volumeMounts:
          - name: rocketmq-data
            mountPath: /home/rocketmq/logs
          - name: rocketmq-data
            mountPath: /home/rocketmq/store
          - name: broker-config
            mountPath: /home/broker.conf
            subPath: broker.conf
        readinessProbe:
          tcpSocket:
            port: 10911
          initialDelaySeconds: 15
          timeoutSeconds: 5
          periodSeconds: 20
      volumes:
      - name: broker-config
        configMap:
          name: broker-a
      #启动依赖
      initContainers:
      - name: init-mq-ns
        image: busybox:latest
        command: ['sh', '-c', "until nslookup mq-ns.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for mq-ns; sleep 2; done"]

  volumeClaimTemplates:
  - metadata:
      name: rocketmq-data
      annotations:
        volume.beta.kubernetes.io/storage-class: "nfs-storage"
    spec:
      accessModes:
        - ReadWriteMany
      resources:
        requests:
          storage: 10Gi

broker-a-s-pods.yaml

apiVersion: v1
kind: Service
metadata:
  labels:
    app: broker-a-s
  name: broker-a-s
  namespace: default
spec:
  # type: NodePort
  type: ClusterIP
  ports:
  - port: 10911
    targetPort: 10911
    name: broker-port
  selector:
    app: broker-a-s
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: broker-a-s
  namespace: default
spec:
  serviceName: broker-a-s
  replicas: 1
  selector:
    matchLabels:
      app: broker-a-s
  template:
    metadata:
     labels:
       app: broker-a-s
    spec:
      # affinity:
      #   #podAntiAffinity 反亲合性
      #   podAntiAffinity:
      #     requiredDuringSchedulingIgnoredDuringExecution:
      #       - labelSelector:
      #           matchExpressions:
      #             - key: "app"
      #               operator: In
      #               values:
      #                 - broker-a-s
      #         topologyKey: "kubernetes.io/hostname"
      containers:
      - name: broker-a-s
        #image: foxiswho/rocketmq:4.8.0   #下面使用的是用官方地址自行构建的镜像,推荐直接使用这个
        image: apacherocketmq/rocketmq:4.8.0
        imagePullPolicy: IfNotPresent
        env:
          - name: TZ
            value: Asia/Shanghai
          - name: NAMESRV_ADDR
            value: "mq-ns.default.svc.cluster.local:9876"
          - name: JAVA_OPT_EXT
            value: "-Duser.home=/home/rocketmq -Xms512M -Xmx512M -Xmn128m"
        command: ["sh","-c","mqbroker -c /home/broker.conf"]
        volumeMounts:
          - name: rocketmq-data
            mountPath: /home/rocketmq/logs
          - name: rocketmq-data
            mountPath: /home/rocketmq/store
          - name: broker-config
            mountPath: /home/broker.conf
            subPath: broker.conf
        readinessProbe:
          tcpSocket:
            port: 10911
          initialDelaySeconds: 15
          timeoutSeconds: 5
          periodSeconds: 20
      volumes:
      - name: broker-config
        configMap:
          name: broker-a-s
        #启动依赖
      initContainers:
      - name: init-mq-ns
        image: busybox:latest
        command: ['sh', '-c', "until nslookup mq-ns.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for mq-ns; sleep 2; done"]

  volumeClaimTemplates:
  - metadata:
      name: rocketmq-data
      annotations:
        volume.beta.kubernetes.io/storage-class: "nfs-storage"
    spec:
      accessModes:
        - ReadWriteMany
      resources:
        requests:
          storage: 10Gi

broker-b-pods.yaml

apiVersion: v1
kind: Service
metadata:
  labels:
    app: broker-b
  name: broker-b
  namespace: default
spec:
  # type: NodePort
  type: ClusterIP
  ports:
  - port: 10911
    targetPort: 10911
    name: broker-port
  selector:
    app: broker-b
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: broker-b
  namespace: default
spec:
  serviceName: broker-b
  replicas: 1
  selector:
    matchLabels:
      app: broker-b
  template:
    metadata:
     labels:
       app: broker-b
    spec:
      # affinity:
      #   #podAntiAffinity 反亲合性
      #   podAntiAffinity:
      #     requiredDuringSchedulingIgnoredDuringExecution:
      #       - labelSelector:
      #           matchExpressions:
      #             - key: "app"
      #               operator: In
      #               values:
      #                 - broker-b
      #         topologyKey: "kubernetes.io/hostname"
      containers:
      - name: broker-b
        #image: foxiswho/rocketmq:4.8.0   #下面使用的是用官方地址自行构建的镜像,推荐直接使用这个
        image: apacherocketmq/rocketmq:4.8.0
        imagePullPolicy: IfNotPresent
        env:
          - name: TZ
            value: Asia/Shanghai
          - name: NAMESRV_ADDR
            value: "mq-ns.default.svc.cluster.local:9876"
          - name: JAVA_OPT_EXT
            value: "-Duser.home=/home/rocketmq -Xms512M -Xmx512M -Xmn128m"
        command: ["sh","-c","mqbroker -c /home/broker.conf"]
        volumeMounts:
          - name: rocketmq-data
            mountPath: /home/rocketmq/logs
          - name: rocketmq-data
            mountPath: /home/rocketmq/store
          - name: broker-config
            mountPath: /home/broker.conf
            subPath: broker.conf
        readinessProbe:
          tcpSocket:
            port: 10911
          initialDelaySeconds: 15
          timeoutSeconds: 5
          periodSeconds: 20
      volumes:
      - name: broker-config
        configMap:
          name: broker-b
        #启动依赖
      initContainers:
      - name: init-mq-ns
        image: busybox:latest
        command: ['sh', '-c', "until nslookup mq-ns.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for mq-ns; sleep 2; done"]

  volumeClaimTemplates:
  - metadata:
      name: rocketmq-data
      annotations:
        volume.beta.kubernetes.io/storage-class: "nfs-storage"
    spec:
      accessModes:
        - ReadWriteMany
      resources:
        requests:
          storage: 10Gi

broker-b-s-pods.yaml

apiVersion: v1
kind: Service
metadata:
  labels:
    app: broker-b-s
  name: broker-b-s
  namespace: default
spec:
  # type: NodePort
  type: ClusterIP
  ports:
  - port: 10911
    targetPort: 10911
    name: broker-port
  selector:
    app: broker-b-s
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: broker-b-s
  namespace: default
spec:
  serviceName: broker-b-s
  replicas: 1
  selector:
    matchLabels:
      app: broker-b-s
  template:
    metadata:
     labels:
       app: broker-b-s
    spec:
      # affinity:
      #   #podAntiAffinity 反亲合性
      #   podAntiAffinity:
      #     requiredDuringSchedulingIgnoredDuringExecution:
      #       - labelSelector:
      #           matchExpressions:
      #             - key: "app"
      #               operator: In
      #               values:
      #                 - broker-b-s
      #         topologyKey: "kubernetes.io/hostname"
      containers:
      - name: broker-b-s
        #image: foxiswho/rocketmq:4.8.0   #下面使用的是用官方地址自行构建的镜像,推荐直接使用这个
        image: apacherocketmq/rocketmq:4.8.0
        imagePullPolicy: IfNotPresent
        env:
          - name: TZ
            value: Asia/Shanghai
          - name: NAMESRV_ADDR
            value: "mq-ns.default.svc.cluster.local:9876"
          - name: JAVA_OPT_EXT
            value: "-Duser.home=/home/rocketmq -Xms512M -Xmx512M -Xmn128m"
        command: ["sh","-c","mqbroker -c /home/broker.conf"]
        volumeMounts:
          - name: rocketmq-data
            mountPath: /home/rocketmq/logs
          - name: rocketmq-data
            mountPath: /home/rocketmq/store
          - name: broker-config
            mountPath: /home/broker.conf
            subPath: broker.conf
        readinessProbe:
          tcpSocket:
            port: 10911
          initialDelaySeconds: 15
          timeoutSeconds: 5
          periodSeconds: 20
      volumes:
      - name: broker-config
        configMap:
          name: broker-b-s
        #启动依赖
      initContainers:
      - name: init-mq-ns
        image: busybox:latest
        command: ['sh', '-c', "until nslookup mq-ns.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for mq-ns; sleep 2; done"]

  volumeClaimTemplates:
  - metadata:
      name: rocketmq-data
      annotations:
        volume.beta.kubernetes.io/storage-class: "nfs-storage"
    spec:
      accessModes:
        - ReadWriteMany
      resources:
        requests:
          storage: 10Gi

mq-console.yaml

apiVersion: v1
kind: Service
metadata:
  labels:
    app: mq-console
  name: mq-cs
  namespace: default
spec:
  type: NodePort
  ports:
  - port: 8080
    targetPort: 8080
    name: console-port
    nodePort: 30808
  selector:
    app: mq-console
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mq-console
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mq-console
  template:
    metadata:
     labels:
       app: mq-console
    spec:
      # affinity:
      #   #podAntiAffinity 反亲合性
      #   podAntiAffinity:
      #     requiredDuringSchedulingIgnoredDuringExecution:
      #       - labelSelector:
      #           matchExpressions:
      #             - key: "app"
      #               operator: In
      #               values:
      #                 - mq-console
      #         topologyKey: "kubernetes.io/hostname"
      containers:
      - name: mq-console
        image: gguilin/rocketmq-console-ng
        imagePullPolicy: IfNotPresent
        env:
          - name: JAVA_OPTS
            value: "-Drocketmq.namesrv.addr=mq-ns.default.svc.cluster.local:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false"
        readinessProbe:
          tcpSocket:
            port: 8080
          initialDelaySeconds: 15
      #启动依赖
      initContainers:
      - name: init-mq-ns
        image: busybox:latest
        command: ['sh', '-c', "until nslookup mq-ns.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for mq-ns; sleep 2; done"]

mq-nmserv.yaml

apiVersion: v1
kind: Service
metadata:
  labels:
    app: mq-namesrv
  name: mq-ns
  namespace: default
spec:
  type: ClusterIP
  ports:
  - port: 9876
    targetPort: 9876
    name: namesrv-port
  selector:
    app: mq-namesrv
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mq-namesrv
  namespace: default
spec:
  serviceName: mq-namesrv
  replicas: 1
  selector:
    matchLabels:
      app: mq-namesrv
  template:
    metadata:
     labels:
       app: mq-namesrv
    spec:
      # affinity:
      #   #podAntiAffinity 反亲合性
      #   podAntiAffinity:
      #     requiredDuringSchedulingIgnoredDuringExecution:
      #       - labelSelector:
      #           matchExpressions:
      #             - key: "app"
      #               operator: In
      #               values:
      #                 - mq-namesrv
      #         topologyKey: "kubernetes.io/hostname"
      containers:
      - name: mq-namesrv
        image: apacherocketmq/rocketmq:4.8.0
        imagePullPolicy: IfNotPresent
        env:
          - name: TZ
            value: Asia/Shanghai
          - name: JAVA_OPT_EXT
            value: "-Duser.home=/home/rocketmq -Xms512M -Xmx512M -Xmn128m"
        command: ["sh","-c","mqnamesrv"]
        readinessProbe:
          tcpSocket:
            port: 9876
          initialDelaySeconds: 15
          timeoutSeconds: 5
          periodSeconds: 20

启动服务

pod/
├── broker-a-pods.yaml
├── broker-a-s-pods.yaml
├── broker-b-pods.yaml
├── broker-b-s-pods.yaml
├── mq-console.yaml
└── mq-nmserv.yaml
#启动服务
kubectl apply  -f  pod/
#查看
kubectl get pod 
NAME                                      READY   STATUS    RESTARTS   AGE
nfs-client-provisioner-55d4f9ff67-z2996   1/1     Running   0          98s
broker-a-0                                0/1     Running   0          56s
broker-b-s-0                              0/1     Running   0          56s
mq-console-5b89d76b99-f5zgd               1/1     Running   0          56s
mq-namesrv-0                              1/1     Running   0          56s
broker-a-s-0                              0/1     Running   0          56s
broker-b-0                                0/1     Running   0          56s

查看pvc

kubectl get pod 
NAME                                      READY   STATUS    RESTARTS   AGE
nfs-client-provisioner-55d4f9ff67-z2996   1/1     Running   0          98s
broker-a-0                                0/1     Running   0          56s
broker-b-s-0                              0/1     Running   0          56s
mq-console-5b89d76b99-f5zgd               1/1     Running   0          56s
mq-namesrv-0                              1/1     Running   0          56s
broker-a-s-0                              0/1     Running   0          56s
broker-b-0                                0/1     Running   0          56s

查看挂载目录

ls /data/nfs/
default-rocketmq-data-broker-a-0-pvc-d0aa28b9-d333-456f-8e1b-4af17848913f    default-rocketmq-data-broker-b-0-pvc-1ac8050c-7798-4df0-ae33-053815642e93
default-rocketmq-data-broker-a-s-0-pvc-ec0ef459-fb70-4e92-810c-012cc2c2a378  default-rocketmq-data-broker-b-s-0-pvc-03b61ec3-7560-4a65-b4ad-838be3c38d68

测试

#发送消息
kubectl exec -it broker-a-0 /bin/bash
sh tools.sh org.apache.rocketmq.example.quickstart.Producer

在这里插入图片描述

#消费消息
kubectl exec -it broker-a-s-0 /bin/bash
sh tools.sh org.apache.rocketmq.example.quickstart.Consumer

在这里插入图片描述

登录console界面

#浏览器登录
http://192.168.50.134:30808/

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值