apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: django-postgres-pvc
  labels:
    app: django
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgres
  namespace: default
  labels:
    app: postgres
spec:
  selector:
    matchLabels:
      app: postgres
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: postgres
    spec:
      volumes:
        - name: postgres-data
          persistentVolumeClaim:
            claimName: django-postgres-pvc
      containers:
      - name: postgres
        image: postgres:latest
        env:
          - name: POSTGRES_DB
            value: django-school-1
          - name: POSTGRES_USER
            value: postgres
          - name: POSTGRES_PASSWORD
            valueFrom:
              secretKeyRef:
                key: password
                name: db-password
        volumeMounts:
          - name: postgres-data
            mountPath: /var/lib/postgresql/data
        ports:
        - containerPort: 5432
          name: postgres

---

apiVersion: v1
kind: Service
metadata:
  name: postgres
  namespace: default
  labels:
    app: postgres
spec:
  ports:
    - port: 5432
  selector:
    app: postgres
  clusterIP: None
