apiVersion: v1
kind: Service
metadata:
  labels:
    app: postgres
  name: postgresql-service
  namespace: postgres
spec:
  ports:
  - name: "5432"
    port: 5432
    targetPort: 5432
    #nodePort: 31655
  #type: NodePort
  selector:
    app: postgres

---

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: postgres
  name: postgresql-16
  namespace: postgres
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
      - env:
        - name: POSTGRES_DB
          value: postgres
        - name: POSTGRES_USER
          value: postgres
        - name: POSTGRES_PASSWORD
          value: postgres
        image: private-repo:5000/postgres:16
        name: postgres
        ports:
        - containerPort: 5432
        volumeMounts:
        - mountPath: "/var/lib/postgresql/data"
          name: postgresql-pv
      volumes:
        - name: postgresql-pv
          persistentVolumeClaim:
            claimName: postgresql-pv-claim
      nodeSelector:
        name: node-1
---

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: postgresql-pv-claim
  namespace: postgres
spec:
  storageClassName: standard
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi

---

apiVersion: v1
kind: PersistentVolume
metadata:
  name: postgresql-pv
  labels:
    type: local
spec:
  storageClassName: standard
  capacity:
    storage: 2Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/kra-data/data/dev/postgres-data"
