docker 和 k8s 部署 rocketmq

1. docker部署

docker run -d -v /u01/data/namesrv/logs:/home/rocketmq/logs --name rmqnamesrv -p 9876:9876 apacherocketmq/rocketmq:4.5.0-alpine sh mqnamesrv

docker run -d -v /u01/data/broker/logs:/home/rocketmq/logs 
              -v /u01/data/broker/store:/home/rocketmq/store --name rmqbroker --link rmqnamesrv:namesrv 
              -e "NAMESRV_ADDR=namesrv:9876" 
              -p 10909:10909 -p 10911:10911 -p 10912:10912 apacherocketmq/rocketmq:rocketmq:4.5.0-alpine sh mqbroker


docker run -d --name rocketmq-dashboard -e "JAVA_OPTS=-Drocketmq.namesrv.addr=10.0.1.56:9876" -p 6765:8080 -t apacherocketmq/rocketmq-dashboard:latest

2. k8s部署
1. 通过storgeclass创建两个备用pvc

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  annotations:
    volume.beta.kubernetes.io/storage-provisioner: fuseim.pri/ifs
  name: rocketmqpv
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 1Gi
  storageClassName: managed-nfs-storage

---  
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  annotations:
    volume.beta.kubernetes.io/storage-provisioner: fuseim.pri/ifs
  name: mqnamepv
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 1Gi
  storageClassName: managed-nfs-storage

  1. 创建deployment
apiVersion: apps/v1
kind: Deployment
metadata:
  name: rocketmq
spec:
  replicas: 1
  selector:
    matchLabels:
      app: rocketmq  
  template:
    metadata:
     labels:
       app: rocketmq
    spec:
      containers:
        - name: broker
          image: hub.aosccs.com.cn:8888/library/rocketmq:4.5.0-alpine
          command: ["sh","mqbroker", "-n","localhost:9876"]
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 10909
            - containerPort: 10911
          volumeMounts:
            - mountPath: /home/rocketmq/logs
              name: rocketmqdata
            - mountPath: /home/rocketmq/store
              name: rocketmqdata
        - name: namesrv
          image: hub.aosccs.com.cn:8888/library/rocketmq:4.5.0-alpine
          command: ["sh","mqnamesrv"]
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 9876
          volumeMounts:
            - mountPath: /home/rocketmq/logs
              name: mqnamesrv
        - name: dashboard
          image: hub.aosccs.com.cn:8888/library/rocketmq-dashboard:latest
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8080       
          env:
            - name: JAVA_OPTS
              value: -Drocketmq.namesrv.addr=localhost:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false                       
      volumes:
      - name: rocketmqdata
        persistentVolumeClaim:
          claimName: rocketmqpv     
      - name: mqnamesrv
        persistentVolumeClaim:
          claimName: mqnamepv                            


3. 创建svc,暴露端口

apiVersion: v1
kind: Service
metadata:
  labels:
    app: rocketmq
  name: console-service
spec:
  ports:
  - nodePort: 31765
    port: 8080
    protocol: TCP
    targetPort: 8080
  selector:
    app: rocketmq
  type: NodePort
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐