项目内使用RabbitMQ,防止RabbitMQ单节点挂机影响服务将RabbitMQ部署在k8s集群内提高可用性

kubectl create cm rabbit-plugins -n sdb-base --from-literal=enabled_plugins="[rabbitmq_shovel,rabbitmq_shovel_management]."

创建deploy.yml 和 service.yml

1.deploy.yml 内容

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    app: rabbitmq
  name: rabbitmq
spec:
  replicas: 1
  selector:
    matchLabels:
      app: rabbitmq
  template:
    metadata:
      labels:
        app: rabbitmq
    spec:
      containers:
      - env:
        - name: RABBITMQ_DEFAULT_USER
          value: "root"
        - name: RABBITMQ_DEFAULT_PASS
          value: "bigdata"
        - name: TZ
          value: Asia/Shanghai
        image: rabbitmq:latest
        imagePullPolicy: IfNotPresent
        name: rabbitmq
        ports:
        - containerPort: 15672
          name: manager
        - containerPort: 5672
          name: broker
        volumeMounts:
        - mountPath: /etc/rabbitmq/enabled_plugins
          name: configfile
          subPath: enabled_plugins
      volumes:
      - name: configfile
        configMap:
         name: rabbit-plugins
         items:
         - key: enabled_plugins
           path: enabled_plugins

需要修改的地方
RABBITMQ_DEFAULT_USER 登陆账号
RABBITMQ_DEFAULT_PASS 登陆密码

2.service.yml 内容

apiVersion: v1
kind: Service
metadata:
  labels:
    app: rabbitmq
  name: rabbitmq
spec:
  type: NodePort
  ports:
  - name: broker
    port: 5672
    protocol: TCP
    targetPort: 5672
    nodePort: 5673
  - name: manangement
    port: 15672
    protocol: TCP
    targetPort: 15672
    nodePort: 15673
  selector:
      app: rabbitmq

需要修改的地方
nodePort 对外访问的端口

3.启动RabbitMQ服务

kubectl apply -f deploy.yml -n sdb-test

kubectl apply -f service.yml -n sdb-test

4.验证访问 IP:15763登陆即可

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐