# # ============LICENSE_START======================================================= # Copyright (C) 2022 Nordix Foundation. # ================================================================================ # 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. # # SPDX-License-Identifier: Apache-2.0 # ============LICENSE_END========================================================= # apiVersion: v1 kind: PersistentVolume metadata: name: postgres-storage-pv-volume namespace: default labels: type: local app: postgres spec: storageClassName: manual capacity: storage: 2Gi accessModes: - ReadWriteOnce hostPath: path: "/var/keycloak/data2" --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: postgres-storage-pv-claim namespace: default labels: app: postgres spec: storageClassName: manual accessModes: - ReadWriteOnce resources: requests: storage: 2Gi --- apiVersion: v1 kind: ConfigMap metadata: name: db-init namespace: default data: init.sql: | SELECT 'CREATE DATABASE capif' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'capif')\gexec DO $$ BEGIN IF NOT EXISTS (SELECT FROM pg_user WHERE usename = 'capif') THEN CREATE USER capif WITH PASSWORD 'capif'; GRANT ALL PRIVILEGES ON DATABASE capif TO capif; END IF; END $$; --- apiVersion: v1 kind: Service metadata: name: postgres namespace: default spec: type: NodePort selector: app: postgres ports: - protocol: TCP port: 5432 nodePort: 30032 targetPort: 5432 --- apiVersion: apps/v1 kind: Deployment metadata: name: postgres namespace: default spec: selector: matchLabels: app: postgres strategy: type: Recreate template: metadata: labels: app: postgres spec: hostname: postgres containers: - image: nexus3.onap.org:10001/postgres name: postgres imagePullPolicy: IfNotPresent env: - name: POSTGRES_DB value: keycloak - name: POSTGRES_USER value: keycloak - name: POSTGRES_PASSWORD value: keycloak - name: PGDATA value: /var/lib/pgsql/data lifecycle: postStart: exec: command: [ "/bin/sh", "-c", "sleep 10 && psql -U $POSTGRES_USER -f /init.sql" ] livenessProbe: exec: command: - /bin/sh - -c - exec pg_isready -U "keycloak" -h 127.0.0.1 -p 5432 initialDelaySeconds: 30 periodSeconds: 10 timeoutSeconds: 5 readinessProbe: exec: command: ["psql", "-w", "-U", $(POSTGRES_USER), "-d", $(POSTGRES_DB), "-c", "SELECT 1"] initialDelaySeconds: 15 timeoutSeconds: 2 ports: - containerPort: 5432 name: postgres volumeMounts: - name: postgres-persistent-storage mountPath: /var/lib/pgsql/data - name : tmp-dir mountPath: /tmp - name: db-init mountPath: /init.sql subPath: init.sql volumes: - name: postgres-persistent-storage persistentVolumeClaim: claimName: postgres-storage-pv-claim - name: tmp-dir hostPath: path: /tmp type: Directory - name: db-init configMap: name: db-init defaultMode: 0755