apiVersion: v1
kind: Service
metadata:
  labels:
    app: pentaho-postgres  # Ensure this label matches the Deployment
  name: postgresql-service
  namespace: pentaho-postgres
spec:
  ports:
  - name: "5432"
    port: 5432
    targetPort: 5432
    # nodePort: 31655  # Uncomment if using NodePort
  # type: NodePort  # Uncomment if using NodePort
  selector:
    app: pentaho-postgres  # Matches the Deployment labels

---

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: pentaho-postgres
  name: postgresql-16
  namespace: pentaho-postgres
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: pentaho-postgres  # Must match the labels of the pod template
  template:
    metadata:
      labels:
        app: pentaho-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  # Ensure the image is accessible
        name: postgres
        ports:
        - containerPort: 5432
        volumeMounts:
        - mountPath: "/var/lib/postgresql/data"
          name: pentaho-postgresql-pv  # Matches the volume name
      volumes:
        - name: pentaho-postgresql-pv
          persistentVolumeClaim:
            claimName: pentaho-postgresql-pv-claim  # Matches the PVC name
      nodeSelector:
        name: node-1  # Ensure this node label exists

---

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

---

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

