official site
Get Started
Docs
Downloading and Installing RabbitMQ
podman
docker
Management Plugin rabbitmq default username and password of guest/guest
1
2
3
| docker run -d -p 5672:5672 -p 15672:15672 --name containerName imageID
docker run -d -p 5672:5672 -p 15672:15672 --name containerName imageName:version
docker run -d --hostname my-rabbit --name some-rabbit -e RABBITMQ_DEFAULT_USER=user -e RABBITMQ_DEFAULT_PASS=password rabbitmq:3.11-management-alpine
|
go to container exit container will not stop
1
2
3
| docker exec -it containerID /bin/bash
# alpine linux
docker exec -it containerID /bin/sh
|
go to container exit container will stop
1
| docker attach containerID
|
exit container
- exit 退出容器伪终端并关闭容器
- ctrl+d 退出容器伪终端并关闭容器
- ctrl+c 退出容器伪终端不关闭容器
- ctrl+p+ctrl+q 退出容器伪终端不关闭容器
rabbitmqadmin
exchange
1
| rabbitmqadmin -u username -p password declare exchange name=exchange type=topic
|
queue
1
| rabbitmqadmin -u username -p password declare queue name=queue durable=true
|
binding
1
| rabbitmqadmin -u username -p password declare binding source=exchange destination=queue routing_key=key
|
k8s
rabbitmq-deployment.yaml
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
| apiVersion: apps/v1
kind: Deployment
metadata:
name: rabbitmq-deployment
labels:
app: rabbitmq
spec:
replicas: 1
selector:
matchLabels:
app: rabbitmq
template:
metadata:
labels:
app: rabbitmq
spec:
containers:
- name: rabbitmq
image: rabbitmq:3.8.26-management-alpine
imagePullPolicy: Never # IfNotPresent Always Never
ports:
- name: manager
containerPort: 15672
protocol: TCP
- name: http
containerPort: 5672
protocol: TCP
env:
- name: RABBITMQ_DEFAULT_USER
value: user
- name: RABBITMQ_DEFAULT_PASS
value: "123456"
volumeMounts:
- name: mq-time
mountPath: /etc/localtime
readOnly: true
volumes:
- name: mq-time
hostPath:
path: /etc/localtime
|
Create the Deployment
1
2
3
4
5
6
7
8
| kubectl apply -f rabbitmq-deployment.yaml
kubectl get deployments
kubectl get deploy -o wide
kubectl get rs
kubectl get rs -w
kubectl get pods
kubectl get pods --show-labels
kubectl describe po -l app=rabbitmq
|
Scaling a Deployment
1
2
| kubectl scale deployment/rabbitmq-deployment --replicas=3
kubectl autoscale deployment/rabbitmq-deployment --min=3 --max=5 --cpu-percent=80
|
update
1
2
3
4
5
| kubectl set image deployment.v1.apps/rabbitmq-deployment rabbitmq=rabbitmq:3.9-management-alpine
kubectl set image deployment/rabbitmq-deployment rabbitmq=rabbitmq:3.9-management-alpine
kubectl rollout status deployment/rabbitmq-deployment
kubectl rollout history deployment/rabbitmq-deployment
kubectl rollout history deployment/rabbitmq-deployment --revision=2
|
rollback
1
2
| kubectl rollout undo deployment/rabbitmq-deployment
kubectl rollout undo deployment/rabbitmq-deployment --to-revision=2
|
Pausing and Resuming a Deployment
1
2
3
4
5
6
7
8
9
| # 暂停
kubectl rollout pause deployment/rabbitmq-deployment
# 执行更新等操作
# do something
# 执行更新等操作
# 恢复 并应用更新
kubectl rollout resume deployment/rabbitmq-deployment
|
rabbitmq-service.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| apiVersion: v1
kind: Service
metadata:
name: rabbitmq-service
spec:
type: NodePort
selector:
app: rabbitmq
ports:
- name: manager
protocol: TCP
port: 15672
targetPort: 15672
nodePort: 30001
- name: http
protocol: TCP
port: 5672
targetPort: 5672
nodePort: 30002
|