k8s rocketmq

# cat rocketmq-acl-configmap.yaml
apiVersion: v1
data:
  plain_acl.yml: |
    # Licensed to the Apache Software Foundation (ASF) under one or more
    # contributor license agreements.  See the NOTICE file distributed with
    # this work for additional information regarding copyright ownership.
    # The ASF licenses this file to You under the Apache License, Version 2.0
    # (the "License"); you may not use this file except in compliance with
    # the License.  You may obtain a copy of the License at
    #
    #     http://www.apache.org/licenses/LICENSE-2.0
    #
    #  Unless required by applicable law or agreed to in writing, software
    #  distributed under the License is distributed on an "AS IS" BASIS,
    #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    #  See the License for the specific language governing permissions and
    #  limitations under the License.

    globalWhiteRemoteAddresses:
    - 10.*.*.*
    - 172.*.*.*
    - 192.168.*.*
    - 168.*.*.*

    accounts:
    #- accessKey: RocketMQ
    #  secretKey: 12345678
    #  whiteRemoteAddress:
    #  admin: false
    #  defaultTopicPerm: DENY
    #  defaultGroupPerm: SUB
    #  topicPerms:
    #  - topicA=DENY
    #  - topicB=PUB|SUB
    #  - topicC=SUB
    #  groupPerms:
    #  # the group should convert to retry topic
    #  - groupA=DENY
    #  - groupB=PUB|SUB
    #  - groupC=SUB

    - accessKey: nfRrMNgtbtjwiEtL
      secretKey: dYtg61JHegz2enae
      whiteRemoteAddress: "*"
      # if it is admin, it could access all resources
      admin: true

kind: ConfigMap
metadata:
  name: acl-config
  namespace: mq

####################################

# cat rocketmq-admin-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: rocketmq-admin
  namespace: mq
spec:
  minReadySeconds: 10
  replicas: 1
  revisionHistoryLimit: 5
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
    type: RollingUpdate
  selector:
    matchLabels:
      app: rocketmq-admin
  template:
    metadata:
     labels:
       app: rocketmq-admin
    spec:
      containers:
      - name: rocketmq-admin
        image: styletang/rocketmq-console-ng
        imagePullPolicy: IfNotPresent
        ports:
          - containerPort: 8080
        env:
          - name: JAVA_OPTS
            #value: "-Drocketmq.namesrv.addr=rocketmq.mq.svc.cluster.local:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false"
            value: "-Drocketmq.config.namesrvAddr=rocketmq.mq.svc.cluster.local:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false"
    #    volumeMounts:
    #      - mountPath: /tmp/rocketmq-console/data/users.properties
    #        name: user-config
    #        subPath: users.properties
    #  volumes:
    #  - name: user-config
    #    configMap:
    #      name: user-config

---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: rocketmq-admin
  name: rocketmq-admin
  namespace: mq
spec:
  ports:
  - name: rocketmq-admin
    port: 8080
    targetPort: 8080
  selector:
    app: rocketmq-admin

####################################

# cat rocketmq-broker-config.yaml
apiVersion: v1
data:
  broker-a.properties: |
    #所属集群名字
    brokerClusterName=rocketmq-cluster
    #broker名字
    brokerName=broker-a
    #0表示Master,>0表示Slave
    brokerId=0
    #删除文件时间点,默认凌晨 4点
    deleteWhen=04
    #文件保留时间,默认 48 小时
    fileReservedTime=48

    brokerRole=ASYNC_MASTER
    flushDiskType=ASYNC_FLUSH
    #nameServer地址,分号分割
    namesrvAddr=rocketmq-a.mq.svc.cluster.local:9876;rocketmq-b.mq.svc.cluster.local:9876
    defaultTopicQueueNums=4
    autoCreateTopicEnable=true
    autoCreateSubscriptionGroup=true
    listenPort=10911
    #commitLog每个文件的大小默认1G
    mapedFileSizeCommitLog=1073741824
    #ConsumeQueue每个文件默认存30W条,根据业务情况调整
    mapedFileSizeConsumeQueue=300000
    aclEnable=true
  broker-b.properties: |
    #所属集群名字
    brokerClusterName=rocketmq-cluster
    #broker名字
    brokerName=broker-b
    #0表示Master,>0表示Slave
    brokerId=0
    #删除文件时间点,默认凌晨 4点
    deleteWhen=04
    #文件保留时间,默认 48 小时
    fileReservedTime=48

    brokerRole=ASYNC_MASTER
    flushDiskType=ASYNC_FLUSH
    #nameServer地址,分号分割
    namesrvAddr=rocketmq-a.mq.svc.cluster.local:9876;rocketmq-b.mq.svc.cluster.local:9876
    defaultTopicQueueNums=4
    autoCreateTopicEnable=true
    autoCreateSubscriptionGroup=true
    listenPort=10911
    #commitLog每个文件的大小默认1G
    mapedFileSizeCommitLog=1073741824
    #ConsumeQueue每个文件默认存30W条,根据业务情况调整
    mapedFileSizeConsumeQueue=300000
    aclEnable=true
kind: ConfigMap
metadata:
  name: broker-config
  namespace: mq

####################################
# cat rocketmq-user-config.yaml
apiVersion: v1
data:
  users.properties: |
    #定义管理员
    admin=admin@123,1

kind: ConfigMap
metadata:
  name: user-config
  namespace: mq

####################################
# cat rocketmq-deployment-a.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: rocketmq-a
  labels:
    app: rocketmq
    version: a
  namespace: mq
spec:
  minReadySeconds: 10
  replicas: 1
  revisionHistoryLimit: 5
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: rocketmq
      version: a
  template:
    metadata:
      labels:
        app: rocketmq
        version: a
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - rocketmq
            topologyKey: "kubernetes.io/hostname"
      containers:
      - name: broker
        image: docker.vimll.com:9888/root/k8s/rocketmq:v4.4.0
        command: ["sh","-c","/opt/rocketmq-4.4.0/bin/mqbroker  -c /opt/rocketmq-4.4.0/conf/broker-a.properties"]
        imagePullPolicy: IfNotPresent
        ports:
        - protocol: TCP
          containerPort: 10909
        - protocol: TCP
          containerPort: 10911
        resources:
          requests:
            cpu: 0.5
            memory: 1.5Gi
          limits:
            cpu: 0.5
            memory: 1.5Gi
        volumeMounts:
          - mountPath: /root/logs
            name: rocketmq-data
            subPath: mq-brokeroptlogs
          - mountPath: /root/store
            name: rocketmq-data
            subPath: mq-brokeroptstore
          - name: broker-config
            mountPath: /opt/rocketmq-4.4.0/conf/broker-a.properties
            subPath: broker-a.properties
          - name: acl-config
            mountPath: /opt/rocketmq-4.4.0/conf/plain_acl.yml
            subPath: plain_acl.yml
        readinessProbe:
          tcpSocket:
            port: 10909
          initialDelaySeconds: 10
          periodSeconds: 5
        livenessProbe:
          tcpSocket:
            port: 10909
          initialDelaySeconds: 120
          periodSeconds: 10
        env:
        - name: JAVA_OPTS
          value: " -Duser.home=/opt"
        - name: JAVA_OPT_EXT
          value: "-server -Xms256m -Xmx256m -Xmn256m"
        - name: MAX_POSSIBLE_HEAP
          value: "4294967296"
      - name: namesrv
        image: docker.vimll.com:9888/root/k8s/rocketmq:v4.4.0
        command: ["sh","mqnamesrv"]
        imagePullPolicy: IfNotPresent
        ports:
          - containerPort: 9876
        resources:
          requests:
            cpu: 0.5
            memory: 1740Mi
          limits:
            cpu: 0.5
            memory: 2048Mi
        readinessProbe:
          tcpSocket:
            port: 9876
          initialDelaySeconds: 10
          periodSeconds: 5
        livenessProbe:
          tcpSocket:
            port: 9876
          initialDelaySeconds: 120
          periodSeconds: 10
        volumeMounts:
          - mountPath: /root/logs
            name: rocketmq-data
            subPath: mq-namesrvoptlogs
          - mountPath: /root/store
            name: rocketmq-data
            subPath: mq-namesrvoptstore
        env:
        - name: MAX_POSSIBLE_HEAP
          value: "1073741824"
      volumes:
      - name: rocketmq-data
        persistentVolumeClaim:
          claimName: rocketmq-data-a
      - name: broker-config
        configMap:
          name: broker-config
      - name: acl-config
        configMap:
          name: acl-config
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: rocketmq
    version: a
  name: rocketmq-a
  namespace: mq
spec:
  ports:
  - name: rocketmq-namesrv
    port: 9876
    targetPort: 9876
  - name: rocketmq-port-10909
    protocol: TCP
    port: 10909
    targetPort: 10909
  - name: rocketmq-port-10911
    protocol: TCP
    port: 10911
    targetPort: 10911
  selector:
    app: rocketmq
    version: a

####################################
# cat rocketmq-deployment-b.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: rocketmq-b
  labels:
    app: rocketmq
    version: b
  namespace: mq
spec:
  minReadySeconds: 10
  replicas: 1
  revisionHistoryLimit: 5
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: rocketmq
      version: b
  template:
    metadata:
     labels:
       app: rocketmq
       version: b
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - rocketmq
            topologyKey: "kubernetes.io/hostname"
      containers:
      - name: broker
        image: docker.vimll.com:9888/root/k8s/rocketmq:v4.4.0
        command: ["sh","-c","/opt/rocketmq-4.4.0/bin/mqbroker  -c /opt/rocketmq-4.4.0/conf/broker-b.properties"]
        imagePullPolicy: IfNotPresent
        ports:
        - protocol: TCP
          containerPort: 10909
        - protocol: TCP
          containerPort: 10911
        resources:
          requests:
            cpu: 0.5
            memory: 1.5Gi
          limits:
            cpu: 0.5
            memory: 1.5Gi
        volumeMounts:
          - mountPath: /root/logs
            name: rocketmq-data
            subPath: mq-brokeroptlogs
          - mountPath: /root/store
            name: rocketmq-data
            subPath: mq-brokeroptstore
          - name: broker-config
            mountPath: /opt/rocketmq-4.4.0/conf/broker-b.properties
            subPath: broker-b.properties
          - name: acl-config
            mountPath: /opt/rocketmq-4.4.0/conf/plain_acl.yml
            subPath: plain_acl.yml
        readinessProbe:
          tcpSocket:
            port: 10909
          initialDelaySeconds: 10
          periodSeconds: 5
        livenessProbe:
          tcpSocket:
            port: 10909
          initialDelaySeconds: 120
          periodSeconds: 10
        env:
        - name: JAVA_OPTS
          value: " -Duser.home=/opt"
        - name: JAVA_OPT_EXT
          value: "-server -Xms256m -Xmx256m -Xmn256m"
        - name: MAX_POSSIBLE_HEAP
          value: "4294967296"
      - name: namesrv
        image: docker.vimll.com:9888/root/k8s/rocketmq:v4.4.0
        command: ["sh","mqnamesrv"]
        imagePullPolicy: IfNotPresent
        ports:
          - containerPort: 9876
        resources:
          requests:
            cpu: 0.5
            memory: 1740Mi
          limits:
            cpu: 0.5
            memory: 2048Mi
        readinessProbe:
          tcpSocket:
            port: 9876
          initialDelaySeconds: 10
          periodSeconds: 5
        livenessProbe:
          tcpSocket:
            port: 9876
          initialDelaySeconds: 120
          periodSeconds: 10

        volumeMounts:
          - mountPath: /root/logs
            name: rocketmq-data
            subPath: mq-namesrvoptlogs
          - mountPath: /root/store
            name: rocketmq-data
            subPath: mq-namesrvoptstore
        env:
          - name: MAX_POSSIBLE_HEAP
            value: "1073741824"
      volumes:
      - name: rocketmq-data
        persistentVolumeClaim:
          claimName: rocketmq-data-b
      - name: broker-config
        configMap:
          name: broker-config
      - name: acl-config
        configMap:
          name: acl-config
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: rocketmq
    version: b
  name: rocketmq-b
  namespace: mq
spec:
  ports:
  - name: rocketmq-namesrv
    port: 9876
    targetPort: 9876
  - name: rocketmq-port-10909
    protocol: TCP
    port: 10909
    targetPort: 10909
  - name: rocketmq-port-10911
    protocol: TCP
    port: 10911
  selector:
    app: rocketmq
    version: b

####################################
# cat rocketmq-pvc.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: rocketmq-data-a
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 50Gi
  storageClassName: rook-ceph-block

---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: rocketmq-data-b
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 50Gi
  storageClassName: rook-ceph-block

####################################
# cat rocketmq-server.yaml
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: rocketmq
  name: rocketmq
  namespace: mq
spec:
  ports:
  - name: rocketmq-namesrv
    port: 9876
  selector:
    app: rocketmq