|
| 1 | +apiVersion: template.openshift.io/v1 |
| 2 | +kind: Template |
| 3 | +metadata: |
| 4 | + name: ${NAME} |
| 5 | + annotations: |
| 6 | + description: >- |
| 7 | + Patroni Postgresql database cluster, with persistent storage. |
| 8 | +labels: |
| 9 | + project: ${PROJECT} |
| 10 | + service: ${NAME} |
| 11 | + app: ${NAME} |
| 12 | + phase: deploy |
| 13 | + app.kubernetes.io/instance: ${NAME} |
| 14 | + app.kubernetes.io/component: database |
| 15 | + app.kubernetes.io/name: patroni |
| 16 | + app.kubernetes.io/managed-by: template |
| 17 | +objects: |
| 18 | +- apiVersion: v1 |
| 19 | + kind: Service |
| 20 | + metadata: |
| 21 | + name: ${NAME}-master |
| 22 | + labels: |
| 23 | + app: ${NAME} |
| 24 | + cluster-name: ${NAME} |
| 25 | + spec: |
| 26 | + ports: |
| 27 | + - port: 5432 |
| 28 | + protocol: TCP |
| 29 | + targetPort: 5432 |
| 30 | + selector: |
| 31 | + role: master |
| 32 | + cluster-name: ${NAME} |
| 33 | + app.kubernetes.io/name: patroni |
| 34 | +- apiVersion: apps/v1 |
| 35 | + kind: StatefulSet |
| 36 | + metadata: |
| 37 | + name: ${NAME} |
| 38 | + app: ${NAME} |
| 39 | + generation: 3 |
| 40 | + labels: |
| 41 | + cluster-name: ${NAME} |
| 42 | + spec: |
| 43 | + podManagementPolicy: Parallel |
| 44 | + replicas: ${{REPLICAS}} |
| 45 | + revisionHistoryLimit: 10 |
| 46 | + selector: |
| 47 | + matchLabels: |
| 48 | + statefulset: ${NAME} |
| 49 | + cluster-name: ${NAME} |
| 50 | + serviceName: ${NAME} |
| 51 | + template: |
| 52 | + metadata: |
| 53 | + labels: |
| 54 | + app: ${NAME} |
| 55 | + statefulset: ${NAME} |
| 56 | + cluster-name: ${NAME} |
| 57 | + app.kubernetes.io/name: patroni |
| 58 | + spec: |
| 59 | + affinity: |
| 60 | + podAntiAffinity: |
| 61 | + requiredDuringSchedulingIgnoredDuringExecution: |
| 62 | + - labelSelector: |
| 63 | + matchExpressions: |
| 64 | + - key: statefulset |
| 65 | + operator: In |
| 66 | + values: |
| 67 | + - ${NAME} |
| 68 | + topologyKey: "kubernetes.io/hostname" |
| 69 | + containers: |
| 70 | + - env: |
| 71 | + - name: POD_IP |
| 72 | + valueFrom: |
| 73 | + fieldRef: |
| 74 | + apiVersion: v1 |
| 75 | + fieldPath: status.podIP |
| 76 | + - name: PATRONI_KUBERNETES_NAMESPACE |
| 77 | + valueFrom: |
| 78 | + fieldRef: |
| 79 | + apiVersion: v1 |
| 80 | + fieldPath: metadata.namespace |
| 81 | + - name: PATRONI_KUBERNETES_LABELS |
| 82 | + value: '{"cluster-name": "${NAME}", "app.kubernetes.io/name": "patroni"}' |
| 83 | + - name: PATRONI_SUPERUSER_USERNAME |
| 84 | + valueFrom: |
| 85 | + secretKeyRef: |
| 86 | + key: superuser-username |
| 87 | + name: ${NAME}-creds |
| 88 | + - name: PATRONI_SUPERUSER_PASSWORD |
| 89 | + valueFrom: |
| 90 | + secretKeyRef: |
| 91 | + key: superuser-password |
| 92 | + name: ${NAME}-creds |
| 93 | + - name: PATRONI_REPLICATION_USERNAME |
| 94 | + valueFrom: |
| 95 | + secretKeyRef: |
| 96 | + key: replication-username |
| 97 | + name: ${NAME}-creds |
| 98 | + - name: PATRONI_REPLICATION_PASSWORD |
| 99 | + valueFrom: |
| 100 | + secretKeyRef: |
| 101 | + key: replication-password |
| 102 | + name: ${NAME}-creds |
| 103 | + - name: APP_USER |
| 104 | + valueFrom: |
| 105 | + secretKeyRef: |
| 106 | + key: database-user |
| 107 | + name: ${NAME}-creds |
| 108 | + - name: APP_PASSWORD |
| 109 | + valueFrom: |
| 110 | + secretKeyRef: |
| 111 | + key: database-password |
| 112 | + name: ${NAME}-creds |
| 113 | + - name: APP_DATABASE |
| 114 | + valueFrom: |
| 115 | + secretKeyRef: |
| 116 | + key: database-name |
| 117 | + name: ${NAME}-creds |
| 118 | + - name: PATRONI_SCOPE |
| 119 | + value: ${NAME} |
| 120 | + - name: PATRONI_NAME |
| 121 | + valueFrom: |
| 122 | + fieldRef: |
| 123 | + apiVersion: v1 |
| 124 | + fieldPath: metadata.name |
| 125 | + - name: PATRONI_LOG_LEVEL |
| 126 | + value: DEBUG |
| 127 | + - name: PATRONI_POSTGRESQL_DATA_DIR |
| 128 | + value: /home/postgres/pgdata/pgroot/data |
| 129 | + - name: PATRONI_POSTGRESQL_PGPASS |
| 130 | + value: /tmp/pgpass |
| 131 | + - name: PATRONI_POSTGRESQL_LISTEN |
| 132 | + value: 0.0.0.0:5432 |
| 133 | + - name: PATRONI_RESTAPI_LISTEN |
| 134 | + value: 0.0.0.0:8008 |
| 135 | + image: ${IMAGE_REGISTRY}/${IMAGE_STREAM_NAMESPACE}/${IMAGE_NAME}:${IMAGE_TAG} |
| 136 | + # Because we are using image reference to a tag, we need to always |
| 137 | + # pull the image otherwise we end up with outdated/out-of-sync |
| 138 | + # image depending on the node where it is running |
| 139 | + imagePullPolicy: Always |
| 140 | + name: ${NAME} |
| 141 | + ports: |
| 142 | + - containerPort: 8008 |
| 143 | + protocol: TCP |
| 144 | + - containerPort: 5432 |
| 145 | + protocol: TCP |
| 146 | + resources: |
| 147 | + requests: |
| 148 | + cpu: ${CPU_REQUEST} |
| 149 | + memory: ${MEMORY_REQUEST} |
| 150 | + limits: |
| 151 | + cpu: ${CPU_LIMIT} |
| 152 | + memory: ${MEMORY_LIMIT} |
| 153 | + readinessProbe: |
| 154 | + initialDelaySeconds: 5 |
| 155 | + timeoutSeconds: 5 |
| 156 | + failureThreshold: 4 |
| 157 | + exec: |
| 158 | + command: |
| 159 | + - /usr/share/scripts/patroni/health_check.sh |
| 160 | + volumeMounts: |
| 161 | + - mountPath: /home/postgres/pgdata |
| 162 | + name: ${NAME} |
| 163 | + dnsPolicy: ClusterFirst |
| 164 | + restartPolicy: Always |
| 165 | + schedulerName: default-scheduler |
| 166 | + securityContext: {} |
| 167 | + serviceAccountName: ${NAME} |
| 168 | + terminationGracePeriodSeconds: 0 |
| 169 | + updateStrategy: |
| 170 | + type: RollingUpdate |
| 171 | + volumeClaimTemplates: |
| 172 | + - metadata: |
| 173 | + annotations: |
| 174 | + volume.beta.kubernetes.io/storage-class: ${STORAGE_CLASS} |
| 175 | + labels: |
| 176 | + app: ${NAME} |
| 177 | + name: ${NAME} |
| 178 | + spec: |
| 179 | + storageClassName: ${STORAGE_CLASS} |
| 180 | + accessModes: |
| 181 | + - ReadWriteOnce |
| 182 | + resources: |
| 183 | + requests: |
| 184 | + storage: ${PVC_SIZE} |
| 185 | +- apiVersion: policy/v1 |
| 186 | + kind: PodDisruptionBudget |
| 187 | + metadata: |
| 188 | + name: ${NAME}-pdb |
| 189 | + spec: |
| 190 | + selector: |
| 191 | + matchLabels: |
| 192 | + app: ${NAME} |
| 193 | + maxUnavailable: 1 |
| 194 | +parameters: |
| 195 | +- name: NAME |
| 196 | + value: patroni |
| 197 | +- name: PROJECT |
| 198 | + value: sims |
| 199 | +- name: REPLICAS |
| 200 | + description: | |
| 201 | + The number of StatefulSet replicas to use. |
| 202 | + displayName: REPLICAS |
| 203 | + value: '3' |
| 204 | +- name: CPU_REQUEST |
| 205 | + description: | |
| 206 | + Starting amount of CPU the container can use. |
| 207 | + displayName: CPU REQUEST |
| 208 | + value: '250m' |
| 209 | +- name: CPU_LIMIT |
| 210 | + description: |
| 211 | + Maximum amount of CPU the container can use. |
| 212 | + displayName: CPU Limit |
| 213 | + value: '1' |
| 214 | +- name: MEMORY_REQUEST |
| 215 | + description: |
| 216 | + Starting amount of memory the container can use. |
| 217 | + displayName: Memory Request |
| 218 | + value: 512Mi |
| 219 | +- name: MEMORY_LIMIT |
| 220 | + description: Maximum amount of memory the container can use. |
| 221 | + displayName: Memory Limit |
| 222 | + value: 512Mi |
| 223 | +- name: IMAGE_STREAM_NAMESPACE |
| 224 | + description: | |
| 225 | + The OpenShift Namespace where the patroni and postgresql |
| 226 | + ImageStream resides. |
| 227 | + displayName: ImageStream Namespace |
| 228 | + value: bcgov-docker-local |
| 229 | +- name: IMAGE_NAME |
| 230 | + description: | |
| 231 | + The Patroni image stream name |
| 232 | + value: patroni-postgres |
| 233 | +- name: IMAGE_TAG |
| 234 | + description: | |
| 235 | + The image tag used to specify which image you would like deployed. |
| 236 | + value: "2.0.1-12.4-latest" |
| 237 | +- name: PVC_SIZE |
| 238 | + description: |
| 239 | + The size of the persistent volume to create. |
| 240 | + displayName: Persistent Volume Size |
| 241 | + value: 2Gi |
| 242 | +- name: STORAGE_CLASS |
| 243 | + value: netapp-file-standard |
| 244 | +- name: IMAGE_REGISTRY |
| 245 | + value: artifacts.developer.gov.bc.ca |
0 commit comments