k8s 部署单节点rabbitmq

k8s 部署单节点rabbitmq

  • 准备 nfs 存储
  10.65.0.111 为nfs server 
  • 创建 nfs 共享目录
mkdir -p /export/nfs_share/volume-mytest/mq-prod 
chmod 777 -R /export/nfs_share/volume-mytest/mq-prod
  • 准备pv、pvc
cat > mq-prod-pvc-pv.yaml << EOF
apiVersion: v1
kind: PersistentVolume
metadata:
  name: mq-prod
  namespace: mytest
  labels:
    name: mq-prod
spec:
  nfs:
    path: /export/nfs_share/volume-mytest/mq-prod
    server: 10.65.0.111
  accessModes: ["ReadWriteMany","ReadOnlyMany"]
  capacity:
    storage: 5Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mq-prod
  namespace: mytest
spec:
  accessModes: ["ReadWriteMany"]
  resources:
    requests:
      storage: 5Gi
EOF

  • 准备 deployment、svc 配置文件
cat > mq-prod-deployment.yaml << EOF
apiVersion: apps/v1beta1
kind: Deployment
metadata:
   namespace: mytest
   name: mq-prod
   labels:
     name: mq-prod
   annotations:
     blackbox_path: /
     blackbox_port: "80"
     blackbox_scheme: http
spec:
  replicas: 1
  template:
    metadata:
     labels:
       name: mq-prod
    spec:
      containers:
      - env:
        - name: RABBITMQ_DEFAULT_VHOST
          value: mymq_vhost
        - name: RABBITMQ_DEFAULT_USER
          value: guest
        - name: RABBITMQ_DEFAULT_PASS
          value: guest  	  
        name: mq-prod
        image: ${mirror_store}/base/${base_version}
        imagePullPolicy: IfNotPresent		# Always、Never、IfNotPresent
        ports:
        - containerPort: 80
        volumeMounts:
        - name: storage
          mountPath: /var/lib/rabbitmq	
        resources:
          limits:
            cpu: "1000m"
            memory: 4096Mi
          requests:
            cpu: "1000m"
            memory: 4096Mi
        securityContext:
          capabilities:
            add:
            - SYS_PTRACE  
      securityContext:
        fsGroup: 999
        runAsUser: 999            
      volumes:
      - name: storage
        persistentVolumeClaim:
          claimName: mq-prod  		
EOF

cat > mq-prod-svc.yaml << EOF
kind: Service
apiVersion: v1
metadata:
  annotations:
    prometheus.io/probe: "true"
  name: mq-prod
  namespace: mytest
  labels:
    name: mq-prod
spec:
  ports:
  - name: mq
    nodePort: 31629
    port: 5672
    protocol: TCP
    targetPort: 5672
  - name: tmq
    nodePort: 31630
    port: 15672
    protocol: TCP
    targetPort: 15672
  selector:
   name: mq-prod
  type: NodePort
EOF


  • 生成配置文件
_kubectl='/opt/kubernetes/client/bin/kubectl --kubeconfig=/opt/kubernetes/config_prod'
${_kubectl} apply -f mq-prod-pvc-pv.yaml
${_kubectl} apply -f mq-prod-deployment.yaml
${_kubectl} apply -f mq-prod-svc.yaml

posted @ 2021-04-27 15:04  lixinliang  阅读(1527)  评论(0编辑  收藏  举报