# Copyright 2024 Apache Software Foundation (ASF)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  labels:
    app.kubernetes.io/name: postgres
  name: postgres-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/name: postgres
  name: postgres
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: postgres
  template:
    metadata:
      labels:
        app.kubernetes.io/name: postgres
    spec:
      containers:
        - name: postgres
          image: postgres
          imagePullPolicy: "IfNotPresent"
          ports:
            - containerPort: 5432
          volumeMounts:
            - name: storage
              mountPath: /var/lib/pgsql/data
          envFrom:
            - secretRef:
                name: postgres-secrets
          readinessProbe:
            exec:
              command: ["pg_isready"]
            initialDelaySeconds: 15
            timeoutSeconds: 2
          livenessProbe:
            exec:
              command: ["pg_isready"]
            initialDelaySeconds: 15
            timeoutSeconds: 2
          resources:
            limits:
              memory: "256Mi"
              cpu: "500m"
      volumes:
        - name: storage
          persistentVolumeClaim:
            claimName: postgres-pvc
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/name: postgres
  name: postgres
spec:
  selector:
    app.kubernetes.io/name: postgres
  ports:
    - port: 5432
