---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ service_name }}
  namespace: {{ name_space }}
  labels:
    app: {{ service_name }}
spec:
  replicas: 1
  selector:
    matchLabels:
      app: {{ service_name }}
  template:
    metadata:
      labels:
        app: {{ service_name }}
        tier: postgreSQL
    spec:
      containers:
        - image: postgres:9.6.2-alpine
          name: {{ service_name }}
          env:
            - name: POSTGRES_USER
              value: postgres
            - name: POSTGRES_DB
              value: pgdb
            - name: POSTGRES_PASSWORD
              value: {{ pg_password }}
          ports:
            - containerPort: 5432
              name: {{ service_name }}
          volumeMounts:
            - name: {{ service_name }}
              mountPath: /var/lib/postgresql/data
      volumes:
        - name: {{ service_name }}
          persistentVolumeClaim:
            claimName: postgres-claim
---
apiVersion: v1
kind: Service
metadata:
  name: {{ service_name }}
  namespace: {{ name_space }}
  labels:
    app: {{ service_name }}
spec:
  type: NodePort
  ports:
    - port: 5432
      targetPort: 5432
  selector:
    app: {{ service_name }}
    tier: postgreSQL
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: postgres-claim
  namespace: {{ name_space }}
  labels:
    app: {{ service_name }}
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
