1.k8s安装rabbitmq

[Kubernetes] - feature - pull image from private registry

运维开发实践 - Kubernetes - 从外部访问k8s服务(Ingress Controller部署)

---
apiVersion: v1
kind: Secret
metadata:
  name: rabbitmq-secret
  namespace: rabbitmq
data:
  username: YWRtaW4K
  password: MTIzNDU2Cg==
type: Opaque
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: rabbitmq
  namespace: rabbitmq
  labels:
    app: rabbitmq
spec:
  replicas: 1
  selector:
    matchLabels:
      app: rabbitmq
  serviceName: rabbitmq-headless
  template:
    metadata:
      labels:
        app: rabbitmq
      annotations:
        prometheus.io/scrape: "true"
    spec:
      containers:
        - name: rabbitmq
          image: registry.cn-hangzhou.aliyuncs.com/yuanli123/rabbitmq:3.9.22-management
          ports:
            - name: tcp-5672
              containerPort: 5672
              protocol: TCP
            - name: tcp-15672
              containerPort: 15672
              protocol: TCP
            - name: tcp-15692
              containerPort: 15692
              protocol: TCP
#                        不知道为什么自己使用的username会多出一个回车字符导致rabbitmq无法识别到
          env:
            - name: RABBITMQ_DEFAULT_USER
              valueFrom:
                secretKeyRef:
                  name: rabbitmq-secret
                  key: username
            - name: RABBITMQ_DEFAULT_PASS
              valueFrom:
                secretKeyRef:
                  name: rabbitmq-secret
                  key: password
            - name: RABBITMQ_USERNAME
              valueFrom:
                secretKeyRef:
                  name: rabbitmq-secret
                  key: username
            - name: RABBITMQ_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: rabbitmq-secret
                  key: password
          resources:
            limits:
              cpu: '1'
              memory: '2Gi'
            requests:
              cpu: '200m'
              memory: '500Mi'
      imagePullSecrets:
        - name: regcred

---
apiVersion: v1
kind: Service
metadata:
  name: rabbitmq-headless
  namespace: rabbitmq
  labels:
    app: rabbitmq
spec:
  ports:
    - name: tcp-rabbitmq-5672
      port: 5672
      targetPort: 5672
      nodePort: 32672
  selector:
    app: rabbitmq
  type: NodePort
---
apiVersion: v1
kind: Service
metadata:
  name: rabbitmq-external
  namespace: rabbitmq
  labels:
    app: rabbitmq-external
spec:
  ports:
    - name: http-rabbitmq-external
      protocol: TCP
      port: 15672
      targetPort: 15672
    - name: http-rabbitmq-metrics
      protocol: TCP
      port: 15692
      targetPort: 15692
  selector:
    app: rabbitmq
  type: ClusterIP

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: rabbitmq-ingress
  namespace: rabbitmq
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  ingressClassName: nginx
  rules:
    - host: rabbitmq.liyuan.com
      http:
        paths:
          - backend:
              service:
                name: rabbitmq-external
                port:
                  number: 15672
            pathType: Prefix
            path: /
    - host: rabbitmq.metrics.com
      http:
        paths:
          - backend:
              service:
                name: rabbitmq-external
                port:
                  number: 15692
            pathType: Prefix
            path: /


2. 测试

# (1) 添加用户
rabbitmqctl add_user liyuan 123456
#(2)rabbitmq 修改密码
rabbitmqctl change_password liyuan 123456
# (3) 设置admin权限
rabbitmqctl set_user_tags liyuan administrator
#(4)rabbitmq 开启网页控制台
cd /opt/bitnami/rabbitmq/sbin/
rabbitmq-plugins list

2.1. 账号: liyuan 密码: 123456

在这里插入图片描述

2.2. prometheus metrics接口工作正常

http://rabbitmq.metrics.com:30001/metrics
在这里插入图片描述

Logo

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

更多推荐