创建pvc

vim rabbitmq-pvc.yaml

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: rabbitmq-data
  namespace: dev
spec:
  storageClassName: k8s-nfs-class
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 1Gi

创建deployment

vim rabbitmq-deploy.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: rabbitmq-dev
  namespace: dev
spec:
  selector:
    matchLabels:
      app: rabbitmq-dev
  template:
    metadata:
      labels:
        app: rabbitmq-dev
    spec:
      containers:
      - name: rabbitmq-dev
        image: rabbitmq:3.6.15-management
        ports:
        - containerPort: 5672
        volumeMounts:
        - name: rabbitmq-persistent-storage
          mountPath: /var/lib/rabbitmq
      volumes:
      - name: rabbitmq-persistent-storage
        persistentVolumeClaim:
          claimName: rabbitmq-data

创建svc

vim rabbitmq-svc.yaml

apiVersion: v1
kind: Service
metadata:
  annotations:
    prometheus.io/probe: "true"
  name: rabbitmq-dev
  namespace: dev
  labels:
    name: rabbitmq-dev
spec:
  selector:
    app: rabbitmq-dev
  type: NodePort
  ports:
  - name: mq
    nodePort: 30672
    port: 5672
    protocol: TCP
    targetPort: 5672
  - name: tmq
    nodePort: 35672
    port: 15672
    protocol: TCP
    targetPort: 15672

然后依次执行

kubectl apply -f rabbitmq-pvc.yaml

查看
kubectl get pvc -n dev | grep rabbitmq

kubectl apply -f rabbitmq-deploy.yaml

kubectl get deployment -n dev | grep rabbitmq
kubectl get pod -n dev | grep rabbitmq

kubectl apply -f rabbitmq-svc.yaml

kubectl get svc -n dev | grep rabbitmq

 

posted on 2021-10-14 18:56  詹利弗  阅读(334)  评论(0编辑  收藏  举报