阿里云ack部署rabbitmq集群
1、创建持久化存储pv和pvc,我整理使用的是阿里云的NAS。
这里需要注意的是:
- 设置下子目录,避免共用 NAS 时,文件组织混乱。
- 给子目录分配权限,我这里设置的是777。
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"
3、创建ingress路由,15672端口映射到指定域名上,然后DNS解析到此ingress的公网IP即可