apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgres-deployment
  labels:
    app: postgres
spec:
#Pods number replicates
  replicas: 1
  #Define how the Deployment identify the pods that it could manage
  selector: 
    matchLabels:
     app: postgres
     #pod template specification
  template:
    metadata:
    #define teh labels for all pods
      labels:
        app: postgres       
    spec:
      containers:
        - name: postgres
          image: postgres:latest
          imagePullPolicy: IfNotPresent
          #open the port to allow send and receive traffic in teh container
          ports:
            - containerPort: 5432
            #read envars from secret file
          envFrom:
            - secretRef:
                name: postgres-secret
          volumeMounts:
          #This is the path in the container on which the mounting will take place.
            - mountPath: /var/lib/postgresql/data
              name: postgredb
            - mountPath: /docker-entrypoint-initdb.d
              name : init-script
      volumes:
        - name: postgredb
          persistentVolumeClaim:
            claimName: postgres-claim
        - name: init-script
          configMap:
             name: postgres-init-script-configmap