blob: 8508e64dd7663e9da3652a0b27d3b931c43bb9e6 [file] [log] [blame]
ktimoneyf27b5132022-03-07 16:48:47 +00001apiVersion: v1
2kind: PersistentVolume
3metadata:
4 name: postgres-storage-pv-volume
5 namespace: default
6 labels:
7 type: local
8 app: postgres
9spec:
10 storageClassName: manual
11 capacity:
12 storage: 2Gi
13 accessModes:
14 - ReadWriteOnce
15 hostPath:
16 path: "/var/keycloak/data2"
17---
18apiVersion: v1
19kind: PersistentVolumeClaim
20metadata:
21 name: postgres-storage-pv-claim
22 namespace: default
23 labels:
24 app: postgres
25spec:
26 storageClassName: manual
27 accessModes:
28 - ReadWriteOnce
29 resources:
30 requests:
31 storage: 2Gi
32---
33apiVersion: v1
34kind: ConfigMap
35metadata:
36 name: db-init
37data:
38 init.sql: |
39 SELECT 'CREATE DATABASE capif'
40 WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'capif')\gexec
41 DO $$
42 BEGIN
43 IF NOT EXISTS (SELECT FROM pg_user WHERE usename = 'capif') THEN
44 CREATE USER capif WITH PASSWORD 'capif';
45 GRANT ALL PRIVILEGES ON DATABASE capif TO capif;
46 END IF;
47 END
48 $$;
49---
50apiVersion: v1
51kind: Service
52metadata:
53 name: postgres
54 namespace: default
55spec:
56 type: NodePort
57 selector:
58 app: postgres
59 ports:
60 - protocol: TCP
61 port: 5432
62 nodePort: 30032
63 targetPort: 5432
64---
65apiVersion: apps/v1
66kind: Deployment
67metadata:
68 name: postgres
69 namespace: default
70spec:
71 selector:
72 matchLabels:
73 app: postgres
74 strategy:
75 type: Recreate
76 template:
77 metadata:
78 labels:
79 app: postgres
80 spec:
81 hostname: postgres
82 containers:
83 - image: nexus3.onap.org:10001/postgres
84 name: postgres
85 imagePullPolicy: IfNotPresent
86 env:
87 - name: POSTGRES_DB
88 value: keycloak
89 - name: POSTGRES_USER
90 value: keycloak
91 - name: POSTGRES_PASSWORD
92 value: keycloak
93 - name: PGDATA
94 value: /var/lib/pgsql/data
95 lifecycle:
96 postStart:
97 exec:
98 command: [ "/bin/sh", "-c", "sleep 10 && psql -U $POSTGRES_USER -f /init.sql" ]
99 livenessProbe:
100 exec:
101 command:
102 - /bin/sh
103 - -c
104 - exec pg_isready -U "keycloak" -h 127.0.0.1 -p 5432
105 initialDelaySeconds: 30
106 periodSeconds: 10
107 timeoutSeconds: 5
108 readinessProbe:
109 exec:
110 command: ["psql", "-w", "-U", $(POSTGRES_USER), "-d", $(POSTGRES_DB), "-c", "SELECT 1"]
111 initialDelaySeconds: 15
112 timeoutSeconds: 2
113 ports:
114 - containerPort: 5432
115 name: postgres
116 volumeMounts:
117 - name: postgres-persistent-storage
118 mountPath: /var/lib/pgsql/data
119 - name : tmp-dir
120 mountPath: /tmp
121 - name: db-init
122 mountPath: /init.sql
123 subPath: init.sql
124 volumes:
125 - name: postgres-persistent-storage
126 persistentVolumeClaim:
127 claimName: postgres-storage-pv-claim
128 - name: tmp-dir
129 hostPath:
130 path: /tmp
131 type: Directory
132 - name: db-init
133 configMap:
134 name: db-init
135 defaultMode: 0755