k8s部署rabbitmq
docker pull rabbitmq:3.9.28-management
1.部署模板
apiVersion: v1
kind: Service
metadata:name: rabbitmq
spec:ports:- name: amqpport: 5672targetPort: 5672- name: managementport: 15672targetPort: 15672selector:app: rabbitmq---apiVersion: apps/v1
kind: StatefulSet
metadata:name: rabbitmq
spec:replicas: 1selector:matchLabels:app: rabbitmqtemplate:metadata:labels:app: rabbitmqspec:imagePullSecrets:- name: harborcontainers:- name: rabbitmqimage: rabbitmq:3.9.28-managementports:- containerPort: 5672- containerPort: 15672resources:limits:cpu: 1024mmemory: 2048Mirequests:cpu: 100mmemory: 200MilivenessProbe:initialDelaySeconds: 30periodSeconds: 10timeoutSeconds: 5successThreshold: 1failureThreshold: 3tcpSocket:port: 5672readinessProbe:initialDelaySeconds: 10periodSeconds: 10timeoutSeconds: 5successThreshold: 1failureThreshold: 3tcpSocket:port: 5672env:- name: RABBITMQ_DEFAULT_USERvalue: "guest"- name: RABBITMQ_DEFAULT_PASSvalue: "guest"volumeMounts:- name: datamountPath: /var/lib/rabbitmq/- name: localtimereadOnly: truemountPath: /etc/localtimevolumes:- name: datahostPath:type: DirectoryOrCreate path: /data/znst/rabbitmq- name: localtimehostPath:type: Filepath: /etc/localtimenodeName: gem-yxyw-t-c02
暴露端口的service
apiVersion: v1
kind: Service
metadata:name: rabbitmq
spec:type: NodePortports:- name: rabbitmqport: 5672targetPort: 5672nodePort: 30004- name: managementport: 15672targetPort: 15672nodePort: 30005selector:app: rabbitmq
实际部署
apiVersion: v1
kind: Service
metadata:name: znst-rabbitmq-test
spec:type: NodePortports:- name: rabbitmqport: 5672targetPort: 5672nodePort: 30004- name: managementport: 15672targetPort: 15672nodePort: 30005selector:app: znst-rabbitmq-test---apiVersion: apps/v1
kind: StatefulSet
metadata:name: znst-rabbitmq-test
spec:replicas: 1selector:matchLabels:app: znst-rabbitmq-testtemplate:metadata:labels:app: znst-rabbitmq-testspec:imagePullSecrets:- name: harborcontainers:- name: rabbitmqimage: rabbitmq:3.9.28-managementports:- containerPort: 5672- containerPort: 15672env:- name: RABBITMQ_DEFAULT_USERvalue: "guest"- name: RABBITMQ_DEFAULT_PASSvalue: "Gd*(53#SALEMQ"resources:limits:cpu: 1024mmemory: 2048Mirequests:cpu: 100mmemory: 200MilivenessProbe:initialDelaySeconds: 30periodSeconds: 10timeoutSeconds: 5successThreshold: 1failureThreshold: 3tcpSocket:port: 5672readinessProbe:initialDelaySeconds: 10periodSeconds: 10timeoutSeconds: 5successThreshold: 1failureThreshold: 3tcpSocket:port: 5672volumeMounts:- name: datamountPath: /var/lib/rabbitmq/- name: localtimereadOnly: truemountPath: /etc/localtimevolumes:- name: datahostPath:type: DirectoryOrCreate path: /data/znst/rabbitmq- name: localtimehostPath:type: Filepath: /etc/localtimenodeName: cn-shenzhen.10.0.21.33
2.服务连接
http://10.0.21.33:30005/ web登录地址
http://10.0.21.33:30004 服务实际调用地址
host: 10.0.21.33
port: 30004
username: guest
password: Gd*(53#SALEMQ
3.rabbitmq新增用户:进入容器或者pod操作
如果想要跨机器登录RabbtiMQ的web管理平台,就需要新建用户,而不能用默认的用户guest。
下面记录一下新增用户的步骤:
1).添加新用户,用户名为root,密码为123456
rabbitmqctl add_user root 123456
2).为该用户分配所有权限
rabbitmqctl set_permissions -p / root “." ".” “.*”
3).设置该用户为管理员角色
rabbitmqctl set_user_tags root administrator
现在就可以用root用户在其他机器上登录RabbitMQ的web管理平台了。