apiVersion: apps/v1
kind: ReplicaSet
metadata:
  labels:
    app: mongodb
  name: mongodb
  namespace: mongodb
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mongodb
  template:
    metadata:
      labels:
        app: mongodb
    spec:
      containers:
      - image: mongodb/mongodb-community-server
        name: mongodb
#        args: ["--dbpath","/data/db"]
        env:
        - name: MONGO_INITDB_ROOT_USERNAME
          value: admin
        - name: MONGO_INITDB_ROOT_PASSWORD
          value: Mongodb01
        volumeMounts:
        - name: "mongo-data-dir"
          mountPath: "/data/db"
      nodeSelector:
        kubernetes.io/arch: amd64
      volumes:
      - name: "mongo-data-dir"
        persistentVolumeClaim:
          claimName: "mongo-data"
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: mongodb
  name: mongodb
  namespace: mongodb
spec:
  ports:
  - port: 27017
    protocol: TCP
    targetPort: 27017
  selector:
    app: mongodb
  type: ClusterIP
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: mongo-data-pv
spec:
  storageClassName: ""
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  mountOptions:
    - hard
    - nfsvers=4.1
  nfs:
    server: 192.168.2.110
    path: /mnt/nfs_share/mongodb
    readOnly: false
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mongo-data
  namespace: mongodb
spec:
  storageClassName: ""
  volumeName: mongo-data-pv
  accessModes:
    - ReadWriteOnce
  volumeMode: Filesystem
  resources:
    requests:
      storage: 1Gi

