postgresql-server.yaml 3.12 KB
---
apiVersion: v1
kind: Service
metadata:
  name: postgresql
spec:
  selector:
    app: postgresql-server
  ports:
    - name: mysql
      protocol: TCP
      port: 5432
      targetPort: 5432
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgresql-server
  labels:
    app: postgresql-server
spec:
  replicas: 1
  progressDeadlineSeconds: 600
  selector:
    matchLabels:
      app: postgresql-server
  template:
    metadata:
      labels:
        app: postgresql-server
    spec:
      restartPolicy: Always
      securityContext:
        runAsUser: 0
        runAsGroup: 0

      volumes:
        - name: postgresql-data
          persistentVolumeClaim:
            claimName: postgresql-data
        - name: postgresql-entrypoint-initdb
          persistentVolumeClaim:
            claimName: postgresql-entrypoint-initdb
        - name: postgresql-scripts
          configMap:
            name: postgresql-scripts
            defaultMode: 0755
        - name: postgresql-preinit-scripts
          configMap:
            name: postgresql-scripts
            defaultMode: 0755
        - name: postgresql-config
          configMap:
            name: postgresql-config
        - name: postgresql-secret
          secret:
            secretName: postgresql-secret
        - name: database-restore
          emptyDir: {}
        - name: etc
          emptyDir: {}

      initContainers:
        - name: wait-for-file
          image: debian
          command: ["/scripts/wait-for-file"]
          volumeMounts:
            - name: postgresql-entrypoint-initdb
              mountPath: /docker-entrypoint-initdb.d
            - name: postgresql-scripts
              mountPath: /scripts
          env:
            - name: WAIT_FOR_FILE
              value: /docker-entrypoint-initdb.d/.restored

        - name: init-postgresql
          image: postgresql
          command: ["/var/scripts/bitnami-postgresql-entrypoint-initContainer.sh"]
          volumeMounts:
            - name: postgresql-scripts
              mountPath: /var/scripts
            - name: postgresql-data
              mountPath: /bitnami/postgresql
            - name: postgresql-config
              mountPath: /var/postgresql-config
            - name: postgresql-secret
              mountPath: /var/postgresql-secret
            - name: postgresql-entrypoint-initdb
              mountPath: /docker-entrypoint-initdb.d
            - name: postgresql-preinit-scripts
              mountPath: /docker-entrypoint-preinitdb.d
            - name: etc
              mountPath: /runtime-etc
          env:
            - name: POSTGRESQL_PASSWORD
              value: "foobar"

      containers:
        - name: postgresql
          image: postgresql
          #securityContext:
          #  runAsUser: 1001
          #  runAsGroup: 1001
          command: ["/var/scripts/bitnami-postgresql-entrypoint-container.sh"]
          args: ["/opt/bitnami/scripts/postgresql/run.sh"]
          volumeMounts:
            - name: postgresql-scripts
              mountPath: /var/scripts
            - name: postgresql-data
              mountPath: /bitnami/postgresql
            - name: etc
              mountPath: /etc