一、拉取rabbitmq的镜像

[root@k8s-fengfan default]# docker pull rabbitmq
Using default tag: latest
Trying to pull repository docker.io/library/rabbitmq ...
sha256:a19f0e3e9b0986948c2072aac82157029df65b01d17ee80b954058245de61a04: Pulling from docker.io/library/rabbitmq
f22ccc0b8772: Pull complete
3cf8fb62ba5f: Pull complete
e80c964ece6a: Pull complete
c1d2d6c5864b: Pull complete
28abf02f449b: Pull complete
04f8f8815c88: Pull complete
0cd2db93bae1: Pull complete
30d57a6c9f84: Pull complete
ff8b150b7ba8: Pull complete
a70b21779fa5: Pull complete
Digest: sha256:a19f0e3e9b0986948c2072aac82157029df65b01d17ee80b954058245de61a04
Status: Downloaded newer image for docker.io/rabbitmq:latest

二、创建一个configmap

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

三、创建Deployment的yaml文件

rabbitmq-deployment.yaml

其中

RABBITMQ_DEFAULT_USER为登入用户名
RABBITMQ_DEFAULT_PASS为登入密码

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: "guest"
        - name: RABBITMQ_DEFAULT_PASS
          value: "guest"
        - 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

四、创建service的yaml文件

rabbitmq-service.yaml

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

五、启动服务

[root@k8s-fengfan dev]# kubectl create -f rabbitmq-deployment.yaml
[root@k8s-fengfan dev]# kubectl create -f rabbitmq-service.yaml

30672为java客户端连接端口
31672为web服务访问端口

Logo

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

更多推荐