Merge "mecm-mepm uninstall playbook added"
[ealt-edge.git] / mep / mepserver / postgres-k8s.yaml
1 # Copyright 2020 Huawei Technologies Co., Ltd.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15
16 # postgres database
17 ---
18 apiVersion: apps/v1
19 kind: Deployment
20 metadata:
21   name: postgres-db
22   namespace: mep
23   labels:
24     app: postgres-db
25 spec:
26   replicas: 1
27   selector:
28     matchLabels:
29       app: postgres-db
30   template:
31     metadata:
32       labels:
33         app: postgres-db
34     spec:
35       volumes:
36         - name: postgres-data
37           persistentVolumeClaim:
38             claimName: postgres-pv-claim
39       containers:
40         - name: postgres-db
41           image: postgres:9.6
42           imagePullPolicy: "IfNotPresent"
43           env:
44             - name: POSTGRES_DB
45               value: kong
46             - name: POSTGRES_USER
47               value: kong
48             - name: POSTGRES_PASSWORD
49               value: kong
50           volumeMounts:
51             - mountPath: /var/lib/postgresql/data
52               name: postgres-data
53           ports:
54             - containerPort: 5432
55
56 # prepare postgres-db
57 ---
58 apiVersion: batch/v1
59 kind: Job
60 metadata:
61   name: prepare-postgre-db
62   namespace: mep
63 spec:
64   template:
65     spec:
66       initContainers:
67         - name: check-db-ready
68           image: postgres:9.6
69           command: ['sh', '-c', 'until pg_isready -h postgres-db -p 5432;
70                     do echo waiting for database; sleep 2; done;']
71       containers:
72         - name: prepare-postgres-db
73           image: kong:1.5.1-alpine
74           env:
75             - name: KONG_DATABASE
76               value: "postgres"
77             - name: KONG_PG_DATABASE
78               value: kong
79             - name: KONG_PG_HOST
80               value: postgres-db
81             - name: KONG_PG_USER
82               value: kong
83             - name: KONG_PG_PASSWORD
84               value: kong
85           command: ['kong']
86           args: ['migrations', 'bootstrap']
87       restartPolicy: Never
88   backoffLimit: 4
89
90
91 # postgres servcie
92 ---
93 apiVersion: v1
94 kind: Service
95 metadata:
96   name: postgres-db
97   namespace: mep
98 spec:
99   selector:
100     app: postgres-db
101   type: ClusterIP
102   ports:
103     - port: 5432