Merge pull request 'feat(deploy): 운영 backend를 prod profile로 돌릴 수 있게 한다(opt-in)' (#4) from feat/backend-prod-profile into main
This commit was merged in pull request #4.
This commit is contained in:
@@ -53,3 +53,74 @@ curl -s -o /dev/null -w '%{http_code}\n' https://hyeonworks.com/api/v1/public/ho
|
||||
- redis가 다시 시작되면 로그인 세션이 모두 풀린다.
|
||||
|
||||
되돌리기: `kubectl -n hyeonworks-prod rollout undo deploy/<이름>`. 그 뒤 이 폴더를 되돌리는 커밋을 만든다.
|
||||
|
||||
## backend prod profile (`prod-profile/`, 아직 켜지 않음)
|
||||
|
||||
운영 backend는 `SPRING_PROFILES_ACTIVE=local`로 돈다. `application-local.yml`은 외부 인프라 없이 혼자
|
||||
뜨는 완결형 설정이라, env로 덮지 않은 값이 개발용으로 남는다. `prod-profile/`은 이것을 `prod`로 바꾸는
|
||||
Kustomize component다. **기본 경로(`kubectl apply -k deploy/production`)에는 들어 있지 않다.**
|
||||
|
||||
### 바꾸면 달라지는 것 (이미지 `46b1cc7` 기준)
|
||||
|
||||
| 항목 | 지금(`local`) | `prod` |
|
||||
| --- | --- | --- |
|
||||
| 시작 검사 | 꺼짐 | 켜짐: `ddl-auto` none/validate, Flyway 안전값, 오류 상세·본문 로깅 금지, H2 금지, DB TLS `verify-full` |
|
||||
| DB 연결 | TLS 검증 없음(pgJDBC 기본 `prefer`) | `sslmode=verify-full`, CNPG CA로 인증서와 호스트 이름을 검증 |
|
||||
| 가명화 salt | 개발용 고정값 `__LOCAL_DEV_…`(보안·감사 로그의 사용자 가명이 예측 가능) | Secret의 무작위 값. 이전 로그의 가명과 이어지지 않는다 |
|
||||
| 앱 로그 수준 | `dev.caskeleton` DEBUG 고정(env `APP_LOG_LEVEL_APP`가 먹지 않음) | env `APP_LOG_LEVEL_APP`(INFO) |
|
||||
| `X-Forwarded-*` | `none` 고정(env가 먹지 않음) | env `APP_SERVER_FORWARD_HEADERS_STRATEGY`(framework) |
|
||||
| JWT issuer | `http://localhost:8081/realms/ca-skeleton` | `https://id.learn.hyeonworks.com/realms/prod` |
|
||||
| 시작 배너 | 출력 | 끔 |
|
||||
|
||||
API 경로(`/api`), 공개 경로, CORS, Redis 세션, object storage(s3), OIDC client는 그대로다.
|
||||
`application.yml`의 API 기본 경로가 `/v1`이라 `PRESENTATION_API_BASE_PATH=/api`를 꼭 준다.
|
||||
|
||||
`backend-prod-env.yaml`은 `application.yml`의 기본값 없는 placeholder 67개 중 Deployment가 아직 주지
|
||||
않는 값을 담는다. 비밀 값은 담지 않는다.
|
||||
|
||||
### 전제 (모두 있어야 켠다)
|
||||
|
||||
1. **Secret 키 둘** `hyeonworks-prod/hyeonworks-secrets`(소유자가 만든다):
|
||||
- `APP_DB_PASSWORD`: 이미 있다.
|
||||
- `APP_PRIVACY_PSEUDONYMIZATION_SALT`: 새로 만든다. 값은 화면에 남기지 않는다.
|
||||
|
||||
```bash
|
||||
salt="$(openssl rand -hex 32)"
|
||||
kubectl -n hyeonworks-prod patch secret hyeonworks-secrets --type merge \
|
||||
-p "{\"stringData\":{\"APP_PRIVACY_PSEUDONYMIZATION_SALT\":\"${salt}\"}}"
|
||||
unset salt
|
||||
```
|
||||
|
||||
2. **ConfigMap `hyeonworks-prod/platform-postgres-ca`**: CNPG CA의 공개 인증서다.
|
||||
|
||||
```bash
|
||||
kubectl -n platform-data get secret platform-postgres-ca -o jsonpath='{.data.ca\.crt}' | base64 -d \
|
||||
| kubectl -n hyeonworks-prod create configmap platform-postgres-ca --from-file=ca.crt=/dev/stdin
|
||||
```
|
||||
|
||||
CNPG는 이 CA를 스스로 갱신한다(2026-11-11 기준 만료 2027-01-11). 갱신되면 이 ConfigMap을 같은
|
||||
명령으로 다시 만들고 backend를 재시작해야 한다. 안 하면 DB 연결이 끊긴다. 오래 가는 CA를 CNPG에
|
||||
주거나 자동으로 복사하는 방법은 플랫폼 쪽(platform-core) 남은 일이다.
|
||||
3. 위 「적용」의 전제(레지스트리 이미지, PriorityClass)가 갖춰져 있다.
|
||||
|
||||
### 켜기
|
||||
|
||||
`../kustomization.yaml`에 아래를 더하는 커밋을 만들고 적용한다.
|
||||
|
||||
```yaml
|
||||
components:
|
||||
- prod-profile
|
||||
```
|
||||
|
||||
```bash
|
||||
kubectl diff -k deploy/production
|
||||
kubectl apply -k deploy/production
|
||||
kubectl -n hyeonworks-prod rollout status deploy/techlog-backend
|
||||
kubectl -n hyeonworks-prod logs deploy/techlog-backend | grep -m1 'profile is active'
|
||||
curl -s -o /dev/null -w '%{http_code}\n' https://hyeonworks.com/api/v1/public/home
|
||||
```
|
||||
|
||||
로그에 `"prod"`가 보이고 마지막 줄이 200이어야 한다. 그 뒤 Studio 로그인을 한 번 해 본다.
|
||||
|
||||
되돌리기: `kubectl -n hyeonworks-prod rollout undo deploy/techlog-backend`. 그다음 `components`를 빼는
|
||||
커밋을 만든다. ConfigMap `techlog-backend-prod-env`는 남아 있어도 해가 없다.
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
# Every ${...} placeholder in application.yml (commit 46b1cc7) that has no
|
||||
# inline default and that the Deployment does not already set. Under the
|
||||
# local profile application-local.yml answered them; under prod they must
|
||||
# come from the environment or startup fails during property binding.
|
||||
# Secrets are not here: APP_DATASOURCE_PASSWORD and
|
||||
# APP_PRIVACY_PSEUDONYMIZATION_SALT come from hyeonworks-secrets.
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: techlog-backend-prod-env
|
||||
data:
|
||||
APP_NAME: tech-log-backend
|
||||
# application.yml defaults the API base path to /v1; every route, the
|
||||
# Ingress and the frontend use /api. local.yml pinned it, prod does not.
|
||||
PRESENTATION_API_BASE_PATH: /api
|
||||
SECURITY_PUBLIC_PATHS: /api/healthcheck, /api/v1/public/**
|
||||
APP_DATASOURCE_URL: jdbc:postgresql://platform-postgres-rw.platform-data.svc.cluster.local:5432/techlog?sslmode=verify-full&sslrootcert=/etc/techlog-db-ca/ca.crt
|
||||
APP_DATASOURCE_USERNAME: techlog
|
||||
APP_DATASOURCE_DRIVER: org.postgresql.Driver
|
||||
APP_DATASOURCE_DDL_AUTO: none
|
||||
APP_DATASOURCE_SHOW_SQL: "false"
|
||||
APP_DATASOURCE_FORMAT_SQL: "false"
|
||||
APP_DATASOURCE_OPEN_IN_VIEW: "false"
|
||||
APP_DATASOURCE_POOL_MAX_SIZE: "10"
|
||||
APP_DATASOURCE_POOL_MIN_IDLE: "2"
|
||||
APP_DATASOURCE_CONNECTION_TIMEOUT: "30000"
|
||||
APP_DATASOURCE_POOL_IDLE_TIMEOUT: "600000"
|
||||
APP_DATASOURCE_POOL_MAX_LIFETIME: "1800000"
|
||||
APP_IDEMPOTENCY_TTL: 24h
|
||||
APP_LOG_LEVEL_SPRING: INFO
|
||||
APP_LOG_LEVEL_WEB: INFO
|
||||
APP_LOG_LEVEL_SQL: WARN
|
||||
APP_LOG_FILE_ENABLED: "false"
|
||||
APP_LOG_FILE_PATH: logs/tech-log-backend.json
|
||||
APP_LOG_FILE_MAX_SIZE: 100MB
|
||||
APP_LOG_FILE_MAX_HISTORY: "14"
|
||||
APP_LOG_FILE_TOTAL_SIZE_CAP: 3GB
|
||||
APP_LOG_ASYNC_ENABLED: "true"
|
||||
APP_LOG_ASYNC_QUEUE_SIZE: "512"
|
||||
APP_LOG_ASYNC_DISCARDING_THRESHOLD: "20"
|
||||
APP_LOG_JSON_TIMEZONE: UTC
|
||||
APP_LOG_JSON_TIMESTAMP_PATTERN: yyyy-MM-dd'T'HH:mm:ss.SSSXXX
|
||||
APP_LOG_JSON_INCLUDE_CALLER_DATA: "false"
|
||||
APP_LOG_JSON_LOGGER_NAME_LENGTH: "0"
|
||||
# Every line, as today. The template suggests sampling <=INFO to 10% for
|
||||
# prod; this site's volume does not need it.
|
||||
APP_LOG_SAMPLING_RATE: "1.0"
|
||||
APP_MESSAGING_BROKER: ""
|
||||
APP_NOTIFICATION_SLACK_PROVIDER: ""
|
||||
APP_NOTIFICATION_EMAIL_PROVIDER: ""
|
||||
APP_SECURITY_CORS_ENABLED: "true"
|
||||
APP_SECURITY_CORS_ORIGINS: https://hyeonworks.com
|
||||
APP_SECURITY_CORS_ALLOWED_METHODS: ""
|
||||
APP_SECURITY_CORS_ALLOWED_HEADERS: "*"
|
||||
APP_SECURITY_CORS_ALLOW_CREDENTIALS: "true"
|
||||
APP_SECURITY_CORS_MAX_AGE: "3600"
|
||||
# Resource-server JWT settings. Studio logs in through the Redis session
|
||||
# (CA_SKELETON_SECURITY_AUTH_MODE=redis-session); JWKS is only fetched
|
||||
# when a bearer token arrives. Point them at the production realm instead
|
||||
# of the local one.
|
||||
APP_SECURITY_JWT_ISSUER: https://id.learn.hyeonworks.com/realms/prod
|
||||
APP_SECURITY_JWT_AUDIENCE: tech-log-bff
|
||||
APP_SERVER_PORT: "8080"
|
||||
APP_SERVER_SHUTDOWN: graceful
|
||||
APP_SERVER_SHUTDOWN_TIMEOUT: 30s
|
||||
APP_SERVER_TOMCAT_MAX_THREADS: "200"
|
||||
APP_SERVER_TOMCAT_MIN_SPARE_THREADS: "10"
|
||||
APP_SERVER_TOMCAT_ACCEPT_COUNT: "100"
|
||||
APP_SERVER_TOMCAT_MAX_CONNECTIONS: "8192"
|
||||
APP_SERVER_TOMCAT_CONNECTION_TIMEOUT: 20s
|
||||
APP_SERVER_COMPRESSION_ENABLED: "true"
|
||||
APP_SERVER_COMPRESSION_MIN_RESPONSE_SIZE: "1024"
|
||||
APP_SERVER_ERROR_INCLUDE_STACKTRACE: never
|
||||
APP_SERVER_ERROR_INCLUDE_MESSAGE: never
|
||||
SPRING_BANNER_MODE: "off"
|
||||
SPRING_MAIN_LAZY_INITIALIZATION: "false"
|
||||
SPRING_MAIN_LOG_STARTUP_INFO: "true"
|
||||
SPRING_THREADS_VIRTUAL_ENABLED: "true"
|
||||
SPRING_JACKSON_DESER_FAIL_ON_UNKNOWN_PROPERTIES: "true"
|
||||
SPRING_JACKSON_DESER_FAIL_ON_NULL_FOR_PRIMITIVES: "true"
|
||||
SPRING_JACKSON_DESER_FAIL_ON_IGNORED_PROPERTIES: "true"
|
||||
SPRING_JACKSON_DESER_READ_UNKNOWN_ENUM_VALUES_AS_NULL: "false"
|
||||
SPRING_JACKSON_SER_WRITE_DATES_AS_TIMESTAMPS: "false"
|
||||
@@ -0,0 +1,42 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: techlog-backend
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: backend
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: techlog-backend-prod-env
|
||||
env:
|
||||
# Turns on the prod startup validators (schema safety, Flyway
|
||||
# safety, error-detail and body-capture off, verify-full TLS,
|
||||
# no H2) and drops local-only answers such as the dev salt.
|
||||
- name: SPRING_PROFILES_ACTIVE
|
||||
value: prod
|
||||
# Explicit env wins over envFrom; keep the direct Spring key in
|
||||
# step with APP_DATASOURCE_URL so both carry verify-full.
|
||||
- name: SPRING_DATASOURCE_URL
|
||||
value: jdbc:postgresql://platform-postgres-rw.platform-data.svc.cluster.local:5432/techlog?sslmode=verify-full&sslrootcert=/etc/techlog-db-ca/ca.crt
|
||||
- name: APP_DATASOURCE_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: hyeonworks-secrets
|
||||
key: APP_DB_PASSWORD
|
||||
- name: APP_PRIVACY_PSEUDONYMIZATION_SALT
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: hyeonworks-secrets
|
||||
key: APP_PRIVACY_PSEUDONYMIZATION_SALT
|
||||
volumeMounts:
|
||||
- name: platform-postgres-ca
|
||||
mountPath: /etc/techlog-db-ca
|
||||
readOnly: true
|
||||
volumes:
|
||||
# Public CA certificate of the platform-postgres CloudNativePG cluster,
|
||||
# copied into this namespace. CloudNativePG rotates it; see README.
|
||||
- name: platform-postgres-ca
|
||||
configMap:
|
||||
name: platform-postgres-ca
|
||||
@@ -0,0 +1,14 @@
|
||||
apiVersion: kustomize.config.k8s.io/v1alpha1
|
||||
kind: Component
|
||||
|
||||
# Opt-in: switches techlog-backend from the local profile to prod. It is NOT
|
||||
# listed in ../kustomization.yaml. Enable it only after the three
|
||||
# prerequisites in ../README.md ("prod profile") exist, by adding
|
||||
# components:
|
||||
# - prod-profile
|
||||
# to ../kustomization.yaml in its own commit.
|
||||
resources:
|
||||
- backend-prod-env.yaml
|
||||
|
||||
patches:
|
||||
- path: backend-prod-patch.yaml
|
||||
Reference in New Issue
Block a user