Merge "Sample consumer to get kafka broker from ICS"
[nonrtric.git] / service-exposure / postgres.yaml
1 #
2 # ============LICENSE_START=======================================================
3 #  Copyright (C) 2022 Nordix Foundation.
4 # ================================================================================
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 # SPDX-License-Identifier: Apache-2.0
18 # ============LICENSE_END=========================================================
19 #
20 apiVersion: v1
21 kind: PersistentVolume
22 metadata:
23   name: postgres-storage-pv-volume
24   namespace: default
25   labels:
26     type: local
27     app: postgres
28 spec:
29   storageClassName: manual
30   capacity:
31     storage: 2Gi
32   accessModes:
33     - ReadWriteOnce
34   hostPath:
35     path: "/var/keycloak/data2"
36 ---
37 apiVersion: v1
38 kind: PersistentVolumeClaim
39 metadata:
40   name: postgres-storage-pv-claim
41   namespace: default
42   labels:
43     app: postgres
44 spec:
45   storageClassName: manual
46   accessModes:
47     - ReadWriteOnce
48   resources:
49     requests:
50       storage: 2Gi
51 ---
52 apiVersion: v1
53 kind: ConfigMap
54 metadata:
55   name: db-init
56   namespace: default
57 data:
58   init.sql: |
59     SELECT 'CREATE DATABASE capif'
60     WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'capif')\gexec
61     DO $$
62     BEGIN
63       IF NOT EXISTS (SELECT FROM pg_user WHERE  usename = 'capif') THEN
64          CREATE USER capif WITH PASSWORD 'capif';
65          GRANT ALL PRIVILEGES ON DATABASE capif TO capif;
66       END IF;
67     END
68     $$;
69 ---
70 apiVersion: v1
71 kind: Service
72 metadata:
73   name: postgres
74   namespace: default
75 spec:
76   type: NodePort
77   selector:
78     app: postgres
79   ports:
80     - protocol: TCP
81       port: 5432
82       nodePort: 30032
83       targetPort: 5432
84 ---
85 apiVersion: apps/v1
86 kind: Deployment
87 metadata:
88   name: postgres
89   namespace: default
90 spec:
91   selector:
92     matchLabels:
93       app: postgres
94   strategy:
95     type: Recreate
96   template:
97     metadata:
98       labels:
99         app: postgres
100     spec:
101       hostname: postgres
102       containers:
103       - image: nexus3.onap.org:10001/postgres
104         name: postgres
105         imagePullPolicy: IfNotPresent
106         env:
107         - name: POSTGRES_DB
108           value: keycloak
109         - name: POSTGRES_USER
110           value: keycloak
111         - name: POSTGRES_PASSWORD
112           value: keycloak
113         - name: PGDATA
114           value: /var/lib/pgsql/data
115         lifecycle:
116           postStart:
117             exec:
118               command: [ "/bin/sh", "-c", "sleep 10 && psql -U $POSTGRES_USER -f /init.sql" ]
119         livenessProbe:
120           exec:
121             command:
122               - /bin/sh
123               - -c
124               - exec pg_isready -U "keycloak" -h 127.0.0.1 -p 5432
125           initialDelaySeconds: 30
126           periodSeconds: 10
127           timeoutSeconds: 5
128         readinessProbe:
129           exec:
130             command: ["psql", "-w", "-U", $(POSTGRES_USER), "-d", $(POSTGRES_DB), "-c", "SELECT 1"]
131           initialDelaySeconds: 15
132           timeoutSeconds: 2
133         ports:
134         - containerPort: 5432
135           name: postgres
136         volumeMounts:
137         - name: postgres-persistent-storage
138           mountPath: /var/lib/pgsql/data
139         - name : tmp-dir
140           mountPath: /tmp
141         - name: db-init
142           mountPath: /init.sql
143           subPath: init.sql
144       volumes:
145       - name: postgres-persistent-storage
146         persistentVolumeClaim:
147           claimName: postgres-storage-pv-claim
148       - name: tmp-dir
149         hostPath:
150           path: /tmp
151           type: Directory
152       - name: db-init
153         configMap:
154           name: db-init
155           defaultMode: 0755