kubernetes快速部署mongodb单机版

  sre

v2-053ff8ce36d32e1f7d353289b27d4394_r.jpg

pvc

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mongo-test
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: "500Gi"
  volumeName: 
  storageClassName: nfs

Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongo-test
spec:
  replicas: 1
  selector:
    matchLabels:
      name: mongo-test
  template:
    metadata:
      labels:
        name: mongo-test
    spec:
      containers:
      - name: mongo-test
        image: mongo:4
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 27017
        volumeMounts:
        - name: mongo-pvc
          mountPath: /data/db
      volumes:
       - name: mongo-pvc
         persistentVolumeClaim:
           claimName: mongo-test

svc

kind: Service
apiVersion: v1
metadata:
  name: mongo-test
spec:
  type: NodePort
  ports:
  - name: mongo
    port: 27017
    nodePort: 30075
    targetPort: 27017
    protocol: TCP
  selector:
    name: mongo-test

mongo init

use test
db.createUser({user: “test”,pwd: “test”,roles: [{ role: “readWrite”, db: “test” }]})

LEAVE A COMMENT

Captcha Code