blob: 8508e64dd7663e9da3652a0b27d3b931c43bb9e6 [file] [log] [blame]
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
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