k8s集群搭建看上篇文章即可:https://blog.csdn.net/weixin_43606975/article/details/119947061?spm=1001.2014.3001.5501
rabbitmq集群搭建1.创建名称空间
kubectl create ns rabbitmq
2.创建pv
cat rabbitmq-pv.yaml kind: PersistentVolume apiVersion: v1 metadata: name: rabbitmq-pv-volume namespace: rabbitmq labels: type: local spec: storageClassName: manual2 capacity: storage: 2Gi accessModes: - ReadWriteonce hostPath: path: "/home/rabbimtq" --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: rabbitmq-pv-claim namespace: rabbitmq spec: storageClassName: manual2 accessModes: - ReadWriteonce resources: requests: storage: 2Gi
3.创建配置文件
cat rabbitmq-config.yaml kind: ConfigMap apiVersion: v1 metadata: name: rabbitmq-cluster-config namespace: rabbitmq labels: addonmanager.kubernetes.io/mode: Reconcile data: enabled_plugins: | [rabbitmq_management,rabbitmq_peer_discovery_k8s]. rabbitmq.conf: | default_user = admin default_pass = 123456 ## Cluster formation. See https://www.rabbitmq.com/cluster-formation.html to learn more. cluster_formation.peer_discovery_backend = rabbit_peer_discovery_k8s cluster_formation.k8s.host = kubernetes.default.svc.cluster.local ## Should RabbitMQ node name be computed from the pod's hostname or IP address? ## IP addresses are not stable, so using [stable] hostnames is recommended when possible. ## Set to "hostname" to use pod hostnames. ## When this value is changed, so should the variable used to set the RABBITMQ_NODENAME ## environment variable. cluster_formation.k8s.address_type = hostname ## How often should node cleanup checks run? cluster_formation.node_cleanup.interval = 30 ## Set to false if automatic removal of unknown/absent nodes ## is desired. This can be dangerous, see ## * https://www.rabbitmq.com/cluster-formation.html#node-health-checks-and-cleanup ## * https://groups.google.com/forum/#!msg/rabbitmq-users/wuOfzEywHXo/k8z_HWIkBgAJ cluster_formation.node_cleanup.only_log_warning = true cluster_partition_handling = autoheal ## See https://www.rabbitmq.com/ha.html#master-migration-data-locality queue_master_locator=min-masters ## See https://www.rabbitmq.com/access-control.html#loopback-users loopback_users.guest = false cluster_formation.randomized_startup_delay_range.min = 0 cluster_formation.randomized_startup_delay_range.max = 2 # default is rabbitmq-cluster's namespace # hostname_suffix cluster_formation.k8s.hostname_suffix = .rabbitmq-cluster.default.svc.cluster.local # memory vm_memory_high_watermark.absolute = 1GB # disk disk_free_limit.absolute = 2GB
4.创建认证
cat rabbitmq-rabac.yaml apiVersion: v1 kind: ServiceAccount metadata: name: rabbitmq-cluster namespace: rabbitmq --- kind: Role apiVersion: rbac.authorization.k8s.io/v1 metadata: name: rabbitmq-cluster namespace: rabbitmq rules: - apiGroups: [""] resources: ["endpoints"] verbs: ["get"] --- kind: RoleBinding apiVersion: rbac.authorization.k8s.io/v1 metadata: name: rabbitmq-cluster namespace: rabbitmq roleRef: apiGroup: rbac.authorization.k8s.io kind: Role name: rabbitmq-cluster subjects: - kind: ServiceAccount name: rabbitmq-cluster namespace: rabbitmq
4.创建service
cat rabbitmq-service.yaml kind: Service apiVersion: v1 metadata: labels: app: rabbitmq-cluster name: rabbitmq-cluster namespace: rabbitmq spec: clusterIP: None publishNotReadyAddresses: true ports: - name: rmqport port: 5672 targetPort: 5672 - name: http port: 15672 selector: app: rabbitmq-cluster --- kind: Service apiVersion: v1 metadata: labels: app: rabbitmq-cluster name: rabbitmq-cluster-manage namespace: rabbitmq spec: ports: - name: http port: 15672 protocol: TCP targetPort: 15672 nodePort: 58080 - name: qmpb protocol: TCP port: 5672 targetPort: 5672 nodePort: 35671 selector: app: rabbitmq-cluster type: NodePort
5.创建StatefulSet
cat rabbitmq-cluster.yaml kind: StatefulSet apiVersion: apps/v1 metadata: labels: app: rabbitmq-cluster name: rabbitmq-cluster namespace: rabbitmq spec: replicas: 3 selector: matchLabels: app: rabbitmq-cluster serviceName: rabbitmq-cluster template: metadata: labels: app: rabbitmq-cluster spec: containers: - args: - -c - cp -v /etc/rabbitmq/rabbitmq.conf ${RABBITMQ_CONFIG_FILE} ; exec docker-entrypoint.sh rabbitmq-server command: - sh env: - name: TZ value: 'Asia/Shanghai' - name: RABBITMQ_ERLANG_cookie value: 'SWvCP0Hrqv43NG7GybHC95ntCJKoW8UyNFWnBEWG8TY=' - name: K8S_SERVICE_NAME value: rabbitmq-cluster - name: POD_IP valueFrom: fieldRef: fieldPath: status.podIP - name: POD_NAME valueFrom: fieldRef: fieldPath: metadata.name - name: POD_NAMESPACE valueFrom: fieldRef: fieldPath: metadata.namespace - name: RABBITMQ_USE_LonGNAME value: "true" - name: RABBITMQ_NODENAME value: rabbit@$(POD_NAME).$(K8S_SERVICE_NAME).$(POD_NAMESPACE).svc.cluster.local - name: RABBITMQ_CONFIG_FILE value: /var/lib/rabbitmq/rabbitmq.conf image: rabbitmq:3.8.3-management imagePullPolicy: IfNotPresent livenessProbe: exec: command: - rabbitmq-diagnostics - status initialDelaySeconds: 60 periodSeconds: 60 timeoutSeconds: 15 name: rabbitmq ports: - containerPort: 15672 name: http protocol: TCP - containerPort: 5672 name: amqp protocol: TCP readinessProbe: exec: command: - rabbitmq-diagnostics - status initialDelaySeconds: 20 periodSeconds: 60 timeoutSeconds: 10 volumeMounts: #容器挂载路径 - mountPath: /etc/rabbitmq name: config-volume readOnly: false - mountPath: /var/lib/rabbitmq name: rabbitmq-storage readOnly: false - name: timezone mountPath: /etc/localtime readOnly: true serviceAccountName: rabbitmq-cluster terminationGracePeriodSeconds: 30 volumes: #物理机路径 - name: config-volume configMap: items: - key: rabbitmq.conf path: rabbitmq.conf - key: enabled_plugins path: enabled_plugins name: rabbitmq-cluster-config - name: timezone hostPath: path: /usr/share/zoneinfo/Asia/Shanghai - name: rabbitmq-storage persistentVolumeClaim: #pvc claimName: rabbitmq-pv-claim
6.启动
kubectl apply -f .
7.查看
kubectl get sts,pod,svc -n rabbitmq
8.查看集群状态并添加进集群
kubectl exec -it pod/rabbitmq-cluster-1 -n rabbitmq bash #进入pod rabbitmqctl --erlang-cookie $(cat $HOME/.erlang.cookie) cluster_status #查看集群状态 rabbitmqctl --erlang-cookie $(cat $HOME/.erlang.cookie) stop_app #停止 rabbitmqctl --erlang-cookie $(cat $HOME/.erlang.cookie) join_cluster rabbit@rabbitmq-cluster-0 #把0节点加入 rabbitmqctl --erlang-cookie $(cat $HOME/.erlang.cookie) join_cluster rabbit@rabbitmq-cluster-2 #把1节点加如 rabbitmqctl --erlang-cookie $(cat $HOME/.erlang.cookie) start_app #启动 rabbitmqctl --erlang-cookie $(cat $HOME/.erlang.cookie) cluster_status #查看是否加入 节点2其它同理
9.查看web界面
k8s-master_ip+58080端口,用户名密码:admin/123456
10.创建队列是否正常
END!!!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)