官方文档: https://github.com/huanwei/rocketmq-operator/blob/master/docs/tutorial.md

git clone https://github.com/huanwei/rocketmq-operator.git

ns

kubectl create ns rocketmq-operator

persistentVolumeClaim

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: namesrvlogs
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: "20"
  volumeName: 
  storageClassName: nfs
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: namesrvstore
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: "20"
  volumeName: 
  storageClassName: nfs

kubectl create -f deploy/00-namesrv.yaml

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: rocketmq-namesrv
  namespace: rocketmq-operator
  labels:
    app: rocketmq-namesrv
spec:
  replicas: 2
  selector:
    matchLabels:
      app: rocketmq-namesrv
  template:
    metadata:
     labels:
       app: rocketmq-namesrv
    spec:
      hostNetwork: true
      dnsPolicy: ClusterFirstWithHostNet
      containers:
      - name: namesrv
        image: registry.cn-hangzhou.aliyuncs.com/sre_pub/rocketmq:4.5.1
        command: ["sh","mqnamesrv"]
        imagePullPolicy: Always
        ports:
          - containerPort: 9876
        volumeMounts:
          - mountPath: /home/rocketmq/logs
            name: namesrvlogs
          - mountPath: /home/rocketmq/store
            name: namesrvstore
      volumes:
      - name: namesrvlogs
        persistentVolumeClaim:
          claimName: namesrvlogs
      - name: namesrvstore
        persistentVolumeClaim:
          claimName: namesrvstore
      #nodeSelector:
           #rocketmq-operator: "on"

kubectl create -f deploy/01-resources.yaml

---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  name: brokerclusters.rocketmq.huanwei.io
  labels:
    release: "0.1"
spec:
  group: rocketmq.huanwei.io
  version: v1alpha1
  scope: Namespaced
  names:
    kind: BrokerCluster
    singular: brokercluster
    plural: brokerclusters

kubectl create -f deploy/02-rbac.yaml

---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: rocketmq-operator
  namespace: rocketmq-operator
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
  name: rocketmq-operator
  namespace: rocketmq-operator
rules:
  - apiGroups:
    - "*"
    resources:
    - "*"
    verbs:
    - "*"
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: rocketmq-operator
  namespace: rocketmq-operator
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind:  ClusterRole
  name: rocketmq-operator
subjects:
- kind: ServiceAccount
  name: rocketmq-operator
  namespace: rocketmq-operator

kubectl create -f deploy/03-deploymentWithConfig.yaml

先打一个标签kubectl label nodes node01 rocketmq-operator=on

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: rocketmq-operator-config
  namespace: rocketmq-operator
  labels:
    app: rocketmq-operator
    release: "0.1.3"
data:
  operator-config.yaml: |
    #namespace: rocketmq-operator
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: rocketmq-operator
  namespace: rocketmq-operator
  labels:
    release: "0.1.3"
    app: rocketmq-operator
spec:
  replicas: 1
  selector:
    matchLabels:
      app: rocketmq-operator
  template:
    metadata:
      labels:
        app: rocketmq-operator
    spec:
      serviceAccountName: rocketmq-operator
      nodeSelector:
        rocketmq-operator: "on"
      volumes:
        - name: rocketmq-operator-config-volume
          configMap:
            name: rocketmq-operator-config
      containers:
      - name: rocketmq-operator-controller
        imagePullPolicy: Always
        image: huanwei/rocketmq-operator:0.1.3
        ports:
        - containerPort: 10254
        volumeMounts:
        - name: rocketmq-operator-config-volume
          mountPath: /etc/rocketmq-operator
        args:
          - --v=4
          - --namespace=rocketmq-operator

service rocketmq-namesrv

apiVersion: v1
kind: Service
metadata:
  name: rocketmq-namesrv
  labels:
    name: rocketmq
spec:
  type: NodePort
  ports:
    - name: mq-namesrv
      port: 9876
      nodePort: 30013
      targetPort: 9876
  selector:
    app: rocketmq-namesrv

kubectl create -f deploy/04-cluster-2m-2s.yaml

---
apiVersion: "rocketmq.huanwei.io/v1alpha1"
kind: BrokerCluster
metadata:
  name: mybrokercluster
  namespace : rocketmq-operator
spec:
  brokerImage: huanwei/rocketmq-broker-k8s:4.4.0
  nameServers: rocketmq-namesrv:9876
  allMaster: false
  replicationMode: SYNC
  groupReplica: 2
  membersPerGroup: 2
  emptyDir: true
  #storageClassName: demo-nfs-storage

dashboard

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: rocketmq-dashboard
  labels:
    name: rocketmq-dashboard
spec:
  template:
    metadata:
      name: rocketmq-dashboard
      labels:
        name: rocketmq-dashboard
    spec:
      containers:
      - name: rocketmq-dashboard
        image: styletang/rocketmq-console-ng
        imagePullPolicy: IfNotPresent
        args: ["JAVA_OPTS=-Drocketmq.config.namesrvAddr=rocketmq-namesrv:9876","-Drocketmq.config.isVIPChannel=false"]
        ports:
        - name: http
          containerPort: 8080

service-dashboard

apiVersion: v1
kind: Service
metadata:
  name: rocketmq-dashboard
  labels:
    name: rocketmq-dashboard
spec:
  type: NodePort
  ports:
    - name: tcp
      port: 8080
      nodePort: 30014
      targetPort: 8080
  selector:
    name: rocketmq-dashboard

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code