From 3f06f1e5b243511ee839f2418f0a9afdeb59cf07 Mon Sep 17 00:00:00 2001 From: wbsong111 Date: Wed, 13 Nov 2024 11:18:38 +0900 Subject: [PATCH] update postgresql-ha/11.9.4 --- charts/postgresql-ha/BUILD-README.md | 228 ++++++++++++++++++++++++++ charts/postgresql-ha/CUSTOM-README.md | 65 ++++++++ 2 files changed, 293 insertions(+) create mode 100644 charts/postgresql-ha/BUILD-README.md create mode 100644 charts/postgresql-ha/CUSTOM-README.md diff --git a/charts/postgresql-ha/BUILD-README.md b/charts/postgresql-ha/BUILD-README.md new file mode 100644 index 0000000..3298325 --- /dev/null +++ b/charts/postgresql-ha/BUILD-README.md @@ -0,0 +1,228 @@ +# postgres-ha 버전 갱신 가이드 + +## 1. git 작업 환경 구성 + +- 서비스 카탈로그 git 다운로드 +``` +$ git clone https://github.com/paasup/service-catalog.git +``` + +- 작업 브랜치로 체크아웃 +``` +$ git checkout -b update-postgresql-ha/11.9.4 +``` + +## 2. helm chart 업데이트 + +### 1) 차트 버전 변경 + +- README-build.md, custom-values.yaml(이름 미정)을 제외한 파일 삭제 + ``` sh + # chart 디렉토리로 이동 + cd ~/service-catalog/charts/postgresql-ha + + # 파일 삭제 전 삭제할 파일 목록 확인 + find . -mindepth 1 \( -name "CUSTOM-README.md" -o -name "BUILD-README.md" -o -name "custom-values.yaml" \) -prune -o -print + + # 파일 삭제 + find . -mindepth 1 \(-name "CUSTOM-README.md" -o -name "BUILD-README.md" -o -name "custom-values.yaml" \) -prune -o -exec rm -rf {} + + ``` + + +- bitnami/postgres-ha 차트 다운로드 + ``` sh + # charts 디렉토리로 이동 + cd ~/service-catalog/charts + + # helm repo 추가 + helm repo add bitnami https://charts.bitnami.com/bitnami + helm repo update + + # helm 차트 + helm pull bitnami/postgresql-ha --version="11.9.4" + + # 차트 변경 + tar xzvf postgresql-ha*.tgz + + # 필요 없는 파일 삭제 + rm postgresql-ha-*.tgz + ``` + +### 2) 차트 수정 사항 반영 + +- 다음은 Postgresql 설정을 추가하기 위하여 수정한 파일 목록 및 내용이다. + + +#### ./template/_configuration.tpl + +- `./template/_configuration.tpl`을 추가 작성한다. +- 파일 내용은 다음과 같다. + +``` yaml +{{/* +Return Postgresql - memory +*/}} +{{- define "postgresql-ha.configuration.postgresql.memory" -}} +{{- $memory := required "postgresql.resources.limits.memory is required" .Values.postgresql.resources.limits.memory | trim -}} +{{- if hasSuffix "Gi" $memory -}} + {{ mul (int (trimSuffix "Gi" $memory)) 1024 }} +{{- else if hasSuffix "GB" $memory -}} + {{ mul (int (trimSuffix "GB" $memory)) 1000 }} +{{- else if hasSuffix "Mi" $memory -}} + {{ int (trimSuffix "Mi" $memory) }} +{{- else if hasSuffix "MB" $memory -}} + {{ int (trimSuffix "MB" $memory) }} +{{- else -}} + {{ fail "`postgresql.resources.limits.memory` 값이 올바른 형식으로 설정되지 않았습니다. (예: '10Gi', '512Mi')" }} +{{- end -}} +{{- end }} + +{{/* +Return Postgresql - shared memory. +*/}} +{{- define "postgresql-ha.configuration.postgresql.sharedMemory" -}} +{{- $memory := include "postgresql-ha.configuration.postgresql.memory" . | int -}} +{{- if gt $memory 256 -}} + {{ div $memory 4 }}Mi +{{- end }} +{{- "" -}} +{{- end }} + +{{/* +Return postgres.conf. +*/}} +{{- define "postgresql-ha.configuration.postgresConf" -}} +{{- $memory := include "postgresql-ha.configuration.postgresql.memory" . | int -}} +listen_addresses = '*' +port = {{ .Values.postgresql.containerPorts.postgresql | quote }} +password_encryption = md5 + +wal_level = 'replica' +archive_mode = 'on' +archive_command = '/bin/true' +max_wal_senders = {{ add .Values.postgresql.replicaCount 2 }} +max_replication_slots = '10' +hot_standby = 'on' +logging_collector = 'on' +log_directory = '/opt/bitnami/postgresql/logs' +log_filename = 'postgresql.log' +log_connections = 'false' +log_disconnections = 'false' +log_hostname = 'true' +client_min_messages = 'error' +pg_stat_statements.max = 10000 +pg_stat_statements.track = all +include_dir = 'conf.d' +pgaudit.log_catalog = 'off' + +wal_buffers = -1 +max_wal_size = 10GB +min_wal_size = 1GB + +shared_buffers = {{ div $memory 4 }}MB + +effective_cache_size = {{ mul (div $memory 4) 3 }}MB +random_page_cost = 2.0 + +{{- if ge $memory 16384 }} +maintenance_work_mem = 2GB +work_mem = {{ div (subf $memory (div $memory 4) 2048) .Values.postgresql.maxConnections }}MB +{{- else if ge $memory 8192 }} +maintenance_work_mem = 1GB +work_mem = {{ div (subf $memory (div $memory 4) 1024) .Values.postgresql.maxConnections }}MB +{{- else }} +maintenance_work_mem = 512MB +work_mem = {{ div (subf $memory (div $memory 4) 512) .Values.postgresql.maxConnections }}MB +{{- end }} + +log_min_duration_statement = 3000 + +{{- $tzEnv := "" }} +{{- range .Values.postgresql.extraEnvVars -}} + {{- if eq "TZ" .name -}} + {{- $tzEnv = .value -}} + {{- end -}} +{{- end -}} +{{- if $tzEnv }} +timezone={{ $tzEnv }} +{{- end -}} +{{- end -}} +``` + + +#### ./template/postgresql/statefulset.yaml + +- `postgresql.resources.limits.memory`에 따라 shared memory 설정을 적용하기 위한 변경 사항이다. +- `./template/postgresql/statefulset.yaml`에 다음 내용을 추가한다. + +``` yaml + volumeMount: + ... + ## line 460 아래 추가 + {{- if ( include "postgresql-ha.configuration.postgresql.sharedMemory" . ) }} + - name: dshm + mountPath: /dev/shm + {{- end }} + ... + voluems: + ... + ## line 600 아래 추가 + {{- if ( include "postgresql-ha.configuration.postgresql.sharedMemory" . ) }} + - name: dshm + emptyDir: + medium: Memory + sizeLimit: {{ include "postgresql-ha.configuration.postgresql.sharedMemory" . }} + {{- end }} +``` + + +#### ./template/postgresql/configmap.yaml + +- `postgresql.resources.limits.memory`에 따라 postgresql에 설정 변경 사항을 반영하기 위해 다음 내용을 추가한다. +- `./template/postgresql/configmap.yaml`에 다음 내용을 추가한다. + +``` yaml +## line 29 아래 추가 +... +{{- else }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ printf "%s-configuration" (include "postgresql-ha.postgresql" .) }} + namespace: {{ include "common.names.namespace" . | quote }} + labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }} + app.kubernetes.io/component: postgresql + {{- if .Values.commonAnnotations }} + annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }} + {{- end }} +data: + postgresql.conf: |- + {{- include "postgresql-ha.configuration.postgresConf" . | nindent 4 }} +... +``` + + +## 3. git push 및 tag 추가 +- 갱신작업 진행후 commit +``` +$ git add . +$ git commit -m "update postgresql-ha/11.9.4" +``` + +- main 브랜치에 체크아웃 후 merge +``` +$ git checkout main +$ git merge update-postgresql-ha/11.9.4 +``` + +- git에 push 후 작업 브랜치 삭제 +``` +$ git push -u origin main +$ git branch -d update-postgresql-ha/11.9.4 +``` + +- git tag 추가 후 push +``` +$ git tag postgresql-ha/11.9.4 +$ git push origin postgresql-ha/11.9.4 +``` diff --git a/charts/postgresql-ha/CUSTOM-README.md b/charts/postgresql-ha/CUSTOM-README.md new file mode 100644 index 0000000..d8823e7 --- /dev/null +++ b/charts/postgresql-ha/CUSTOM-README.md @@ -0,0 +1,65 @@ + +# Postgresql-HA 배포 + +## 1. 배포시 주의 사항 +- 해당 차트 배포 시 `postgresql.resource.limits.memory`에 대한 설정을 반드시 해야한다. + 설정하지 않을 시 배포가 되지 않는다. + +## 2.custom-values.yaml 설명 + +- custom-values.yaml에 정의된 값에 대한 설명이다. + +### 1) 전역 설정 +- private 환경 배포시 사용한다. + +| Name | 설명 | 기본값 | +| ---------------------- | ------------------------------------------------------------ | ------ | +| `global.imageRegistry` | 오프라인 설치 시에 설정.
paasup 설치시에는 "paasup.io"으로 설정 | `""` | + + + +### 2) Postgresql 설정 + +- 해당 차트의 기본 배포설정은 싱글 배포이다. +- HA 배포를 원할 시 `postgresql.replicaCount`를 2이상으로 설정하고 [pgpool](#ha-배포)에 대한 추가 설정이 필요하다. + +| Name | 설명 | 기본값 | +| --------------------------- | ------------------------------------------------------------ | ----------------------- | +| `postgresql.image.tag` | postgresql 실행 시 사용할 이미지의 tag를 설정.
helm 차트의 기본값을 사용. 버전 변경 시에는 차트 변경을 우선 고려하고 변경 불가 상황에서만 변경. | "" | +| `postgresql.username` | postgresql의 username | 'postgres' | +| `postgresql.password` | postgresql의 password | 'postgres' | +| `postgresql.repmgrUsername` | repmgr의 username | 'postgres' | +| `postgresql.repmgrPaasword` | repmgr의 password | 'postgres' | +| `postgresql.replicaCount` | postgresql pod에 대한 replicas 설정.
기본 값은 싱글 배포를 위해 1로 되어 있다. 2 이상 설정 시 ha 구성을 위하여 pgpool의 설정이 필요하다. | 1 | +| `postgresql.maxConnections` | postgresql의 Maximum connections 설정 | `"100"` | +| `postgresql.sharedPreloadLibraries` | Shared preload libraries (comma-separated list) | `"repmgr, pgaudit, pg_stat_statements"` | +| `postgresql.initdbScripts` | initdb scripts. 예시는 custom-values.yaml 참고 | `{}` | +| `postgresql.extraEnvVars` | postgresql의 pod에 추가할 환경 변수.
기본 설정은 timezon 환경변수가 추가되어 있음 | custom-values.yaml 참고 | +| `postgresql.resources` | postgresql의 pod의 cpu, memory 설정. | custom-values.yaml 참고 | +| `postgresql.tolerations` | postgresql의 pod 배포를 위한 toleration. | [] | +| `postgresql.nodeSelector` | postgresql의 pod가 배포되는 node 설정. | {} | + + + +### 3) pgpool 설정 +#### 싱글 배포 시 설정(기본 설정) + +| Name | 설명 | 기본값 | +| ---------------------- | ------------------------------------------------------------ | -------------- | +| `pgpool.adminPassword` | pgpool의 관리자 패스워드. | `"postgresql"` | +| `pgpool.replicaCount` | pgpool pod에 대한 replica 수.
`postgresql.replicaCount`가 2 이상일 때, custom-values.yaml에서 `replicaCount: 0`을 주석처리하고 그 아래 있는 설정에 대한 주석을 해제한다. | `0` | + +#### HA 배포 +- `postgresql.replicaCount`가 2 이상일 때 사용한다. (기본은 주석처리되어 있음) +- `postgresql.maxConnections`에 따라서 다음과 같이 설정한다. + - `pgpool.maxPool * pgpool.numInitChildren < postgresql.maxConnections` + +| Name | 설명 | 기본값 | +| ----------------------------- | ------------------------------------------------------------ | ----------------------- | +| `pgpool.adminPassword` | pgpool의 관리자 패스워드. | `"postgresql"` | +| `pgpool.replicaCount` | pgpool pod에 대한 replica 수.
`custom-values.yaml에서 `replicaCount: 0`을 주석처리하고
그 아래 있는 설정에 대한 주석을 해제한다. | `2` | +| `pgpool.authenticationMethod` | pgpool authentication method. PSQL < 14일 때는 'md5'로 설정. | `"scram-sha-256"` | +| `postgresql.maxPool` | pgpool의 각 child 프로세스가 유지하는 Postgresql에 대한 최대 연결 수 | 4 | +| `postgresql.numInitChildren` | pgpool가 prefork하는 child 프로세스 수. | 32 | +| `postgresql.resources` | pgpool의 pod의 cpu, memory 설정. | custom-values.yaml 참고 | +