2022-02-10:k8s安装mongo,yaml如何写?

答案2022-02-10:

yaml如下:

apiVersion: v1
kind: Service
metadata:
  labels:
    app: mongo
  name: mongo
  namespace: moonfdd
spec:
  ports:
    - port: 27017
      protocol: TCP
      targetPort: 27017
  selector:
    app: mongo
  type: NodePort
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: mongo
  name: mongo
  namespace: moonfdd
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mongo
  template:
    metadata:
      labels:
        app: mongo
    spec:
      containers:
        - image: mongo
          imagePullPolicy: IfNotPresent
          name: mongo
          volumeMounts:
            - mountPath: /data/db
              name: volv
      volumes:
        - hostPath:
            path: /root/k8s/moonfdd/mongo/data/db
            type: DirectoryOrCreate
          name: volv

结果如下: 图片


mongo的yaml