apiVersion: apps/v1
# k8s config file type
kind: Deployment
metadata:
  # deployment name
  name: mongodb-deployment
  # service selector matches with depl. label
  labels:
    app: mongodb
spec:
  replicas: 1
  selector: 
    # depl. selector label matches with template/pod label 
    matchLabels:
      app: mongodb
  # blue print of the Pod
  template:
    metadata:
      labels:
        app: mongodb
    spec:
      containers:
      - name: mongodb
        image: mongo
        # it matches with Service targetPort
        ports:
        - containerPort: 27017
        # environmnt variables section.
        # user and password shouldn't be expossed directly in yamel,
        # so a Secret is created 1st to reference
        env:
        - name: MONGO_INITDB_ROOT_USERNAME
          valueFrom:
            secretKeyRef:
              name: mongodb-secret
              key: mongo-root-username
        - name: MONGO_INITDB_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mongodb-secret
              key: mongo-root-password