# 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 ```