1、创建持久化存储pv和pvc,我整理使用的是阿里云的NAS。

这里需要注意的是:

  • 设置下子目录,避免共用 NAS 时,文件组织混乱。
  • 给子目录分配权限,我这里设置的是777。

阿里云ack部署rabbitmq集群_子目录

2、创建服务部署的yaml文件。

cat mq-Account.yaml 
apiVersion: v1
kind: ServiceAccount
metadata:name: rabbitmqnamespace: service-rabbitmq
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:name: rabbitmqnamespace: service-rabbitmq
rules:
- apiGroups: [""]resources: ["endpoints"]verbs: ["get"]
- apiGroups: [""]resources: ["events"]verbs: ["create"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:name: rabbitmqnamespace: service-rabbitmq
subjects:
- kind: ServiceAccountname: rabbitmq
roleRef:apiGroup: rbac.authorization.k8s.iokind: Rolename: rabbitmqcat mq-Configmap.yaml 
apiVersion: v1
kind: ConfigMap
metadata:name: rabbitmq-confignamespace: service-rabbitmq
data:rabbitmq.conf: |cluster_formation.peer_discovery_backend = k8scluster_formation.k8s.host = kubernetes.default.svc.cluster.localcluster_formation.k8s.address_type = hostnamecluster_formation.k8s.service_name = rabbitmq-headlessqueue_master_locator=min-mastersenabled_plugins: |[rabbitmq_management,rabbitmq_peer_discovery_k8s,rabbitmq_delayed_message_exchange].
# 按需启用插件cat mq-HeadlessService.yaml 
apiVersion: v1
kind: Service
metadata:name: rabbitmq-headlessnamespace: service-rabbitmq
spec:clusterIP: Noneports:- name: epmdport: 4369protocol: TCPtargetPort: 4369- name: cluster-linksport: 25672protocol: TCPtargetPort: 25672selector:app: rabbitmqsessionAffinity: Nonetype: ClusterIPcat mq-Service.yaml 
apiVersion: v1
kind: Service
metadata:name: rabbitmq-externalnamespace: service-rabbitmq
spec:ports:- name: httpport: 15672protocol: TCPtargetPort: 15672- name: amqpport: 5672protocol: TCPtargetPort: 5672selector:app: rabbitmqsessionAffinity: Nonetype: ClusterIPcat mq-Service.yaml 
apiVersion: v1
kind: Service
metadata:name: rabbitmq-externalnamespace: service-rabbitmq
spec:ports:- name: httpport: 15672protocol: TCPtargetPort: 15672- name: amqpport: 5672protocol: TCPtargetPort: 5672selector:app: rabbitmqsessionAffinity: Nonetype: ClusterIP
[root@jumpserver test1]# cat mq-StatefulSet.yaml 
apiVersion: apps/v1
kind: StatefulSet
metadata:name: rabbitmq-clusternamespace: service-rabbitmq
spec:replicas: 3selector:matchLabels:app: rabbitmqserviceName: rabbitmq-headlesstemplate:metadata:labels:app: rabbitmqspec:serviceAccountName: rabbitmqsecurityContext:fsGroup: 999runAsUser: 999runAsGroup: 999volumes:- name: config-volumeconfigMap:name: rabbitmq-configitems:- key: rabbitmq.confpath: "rabbitmq.conf"- key: enabled_pluginspath: "enabled_plugins"- name: rabbitmq-config-rwemptyDir: {}- name: rabbitmq-datapersistentVolumeClaim:claimName: nas-service-rabbitmq-pvcinitContainers:- name: initimage: harbor.hkfuliao.com/library/busybox:latestvolumeMounts:- name: config-volumemountPath: /tmp/rabbitmq- name: rabbitmq-config-rwmountPath: /etc/rabbitmqcommand:- sh- -c- cp /tmp/rabbitmq/rabbitmq.conf /etc/rabbitmq/rabbitmq.conf && echo '' >> /etc/rabbitmq/rabbitmq.conf;cp /tmp/rabbitmq/enabled_plugins /etc/rabbitmq/enabled_pluginscontainers:- name: rabbitmqimage: harbor.hkfuliao.com/service-rabbitmq/rabbitmq:3.9.13-managementlivenessProbe:exec:command: ["rabbitmq-diagnostics", "status"]initialDelaySeconds: 60periodSeconds: 60timeoutSeconds: 15readinessProbe:exec:command: ["rabbitmq-diagnostics", "ping"]initialDelaySeconds: 60periodSeconds: 60timeoutSeconds: 10ports:- name: amqpcontainerPort: 5672protocol: TCP- name: management-httpcontainerPort: 15672protocol: TCP- name: epmdcontainerPort: 4369protocol: TCPresources: limits:memory: 2Girequests:memory: 2Gienv:- name: MY_POD_NAMEvalueFrom:fieldRef:fieldPath: metadata.name  # get pod.metadata.name, e.g. rabbitmq-cluster-0- name: MY_POD_NAMESPACEvalueFrom:fieldRef:fieldPath: metadata.namespace  # get pod.metadata.namespace- name: RABBITMQ_DEFAULT_USERvalue: "admin"- name: RABBITMQ_DEFAULT_PASSvalue: "admin@123"- name: RABBITMQ_USE_LONGNAMEvalue: "true"- name: K8S_SERVICE_NAMEvalue: "rabbitmq-headless"- name: RABBITMQ_NODENAMEvalue: "rabbit@$(MY_POD_NAME).$(K8S_SERVICE_NAME).$(MY_POD_NAMESPACE).svc.cluster.local"- name: K8S_HOSTNAME_SUFFIXvalue: .$(K8S_SERVICE_NAME).$(MY_POD_NAMESPACE).svc.cluster.local- name: RABBITMQ_ERLANG_COOKIEvalue: "91/rHX2a3GZw3RCHT1Q9y/G0Wo3cbX3qS06DyD4fAUs="    # generator by: echo $(openssl rand -base64 32)volumeMounts:- name: rabbitmq-config-rwmountPath: "/etc/rabbitmq"- name: rabbitmq-datamountPath: "/var/lib/rabbitmq/mnesia"
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
  • 121.
  • 122.
  • 123.
  • 124.
  • 125.
  • 126.
  • 127.
  • 128.
  • 129.
  • 130.
  • 131.
  • 132.
  • 133.
  • 134.
  • 135.
  • 136.
  • 137.
  • 138.
  • 139.
  • 140.
  • 141.
  • 142.
  • 143.
  • 144.
  • 145.
  • 146.
  • 147.
  • 148.
  • 149.
  • 150.
  • 151.
  • 152.
  • 153.
  • 154.
  • 155.
  • 156.
  • 157.
  • 158.
  • 159.
  • 160.
  • 161.
  • 162.
  • 163.
  • 164.
  • 165.
  • 166.
  • 167.
  • 168.
  • 169.
  • 170.
  • 171.
  • 172.
  • 173.
  • 174.
  • 175.
  • 176.
  • 177.
  • 178.
  • 179.
  • 180.
  • 181.
  • 182.
  • 183.
  • 184.
  • 185.
  • 186.
  • 187.
  • 188.
  • 189.
  • 190.
  • 191.
  • 192.
  • 193.
  • 194.
  • 195.
  • 196.
  • 197.
  • 198.
  • 199.
  • 200.
  • 201.
  • 202.
  • 203.
  • 204.
  • 205.
  • 206.
  • 207.
  • 208.
  • 209.
  • 210.
  • 211.
  • 212.
  • 213.
  • 214.
  • 215.
  • 216.
  • 217.
  • 218.
  • 219.
  • 220.
  • 221.
  • 222.
  • 223.
  • 224.
  • 225.
  • 226.
  • 227.
  • 228.
  • 229.
  • 230.
  • 231.
  • 232.
  • 233.
  • 234.
  • 235.
  • 236.
  • 237.

3、创建ingress路由,15672端口映射到指定域名上,然后DNS解析到此ingress的公网IP即可

阿里云ack部署rabbitmq集群_TCP_02