文章目录
前言
使用rabbitmq-operator在k8s集群上部署rabbitmq实例。时区设置为上海
一、rabbitmq-operator
官网地址:https://www.rabbitmq.com/kubernetes/operator/install-operator
github上的tag列表网址:https://github.com/rabbitmq/cluster-operator/tags
二、进行部署
1.部署cluster-operator
首先获取cluster-operator.yml文件,然后增加上海时区的参数
我使用的是v2.9.0版本
shell
wget https://github.com/rabbitmq/cluster-operator/releases/download/v2.9.0/cluster-operator.yml
增加上海时区的参数
yaml
spec:
containers:
- command:
- /manager
env:
- name: OPERATOR_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: TZ
value: Asia/Shanghai
创建operator
shell
kubectl create -f cluster-operator.yml
2.创建自己需要的特定命名空间
准备rabbitmq-namespace.yaml文件
yaml
#https://www.rabbitmq.com/kubernetes/operator/install-operator
apiVersion: v1
kind: Namespace
metadata:
name: slw-rabbitmq # Change this value if you want a different namespace name
labels:
name: slw-rabbitmq # Change this value to match metadata.name
创建命名空间
shell
kubectl create -f rabbitmq-namespace.yaml
3.创建rabbitmq的instance
准备rabbitmq.yaml文件.
时区配置需要写在override下,卸载spec.env是不支持的。
yaml
apiVersion: rabbitmq.com/v1beta1
kind: RabbitmqCluster
metadata:
name: rabbitmqcluster-slw
namespace: slw-rabbitmq
labels:
app: rabbitmq
spec:
image: docker.io/rabbitmq:3.13.2-management
replicas: 3
service:
type: ClusterIP
#type: NodePort
persistence:
storageClassName: rook-cephfs
storage: 5Gi
rabbitmq:
additionalConfig: |
default_user = guest
default_pass = guest
override:
statefulSet:
spec:
template:
spec:
containers:
- name: rabbitmq
env:
- name: TZ
value: Asia/Shanghai
通过yaml文件创建实例
shell
kubectl create -f rabbitmq.yaml
4.创建nodeport访问
配置文件准备rabbitmq-nodeport.yaml
yaml
kind: Service
apiVersion: v1
metadata:
name: rabbitmqcluster-slw-nodeport
namespace: slw-rabbitmq
labels:
app: rabbitmq
app.kubernetes.io/component: rabbitmq
app.kubernetes.io/name: rabbitmqcluster-slw
app.kubernetes.io/part-of: rabbitmq
spec:
ports:
- name: amqp
protocol: TCP
appProtocol: amqp
port: 5672
targetPort: 5672
nodePort: 30903
- name: management
protocol: TCP
appProtocol: http
port: 15672
targetPort: 15672
nodePort: 30904
- name: prometheus
protocol: TCP
appProtocol: prometheus.io/metrics
port: 15692
targetPort: 15692
nodePort: 30905
selector:
app.kubernetes.io/name: rabbitmqcluster-slw
type: NodePort
sessionAffinity: None
externalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
通过yaml文件创建service
shell
kubectl create -f rabbitmq-nodeport.yaml
结果验证
通过网页访问管理页面http://IP:30904/
账号密码均为guest