diff --git a/deploy/production/README.md b/deploy/production/README.md new file mode 100644 index 0000000..bba926a --- /dev/null +++ b/deploy/production/README.md @@ -0,0 +1,55 @@ +# hyeonworks.com 운영 매니페스트 + +`hyeonworks-prod` namespace의 앱 쪽 객체 정본이다(소유자 결정 2026-11-11: 앱 쪽은 tech-log repo +`deploy/`). 플랫폼 쪽(Namespace, techlog DB Role·Database, 다른 namespace의 NetworkPolicy·Probe· +경보·대시보드)은 platform-core `services/tenants/techlog`가 맡는다. `hyeonworks-secrets` Secret은 +Git 밖에서 만든다. + +| 파일 | 객체 | +| --- | --- | +| `backend-*.yaml` | `techlog-backend` Deployment, Service `techlog-backend`·`techlog-management`, ServiceMonitor, ConfigMap `techlog-logging` | +| `redis-*.yaml` | 세션 저장소 `redis` Deployment·Service(저장 안 함, 재시작하면 로그인이 풀린다) | +| `frontend-*.yaml` | `techlog-frontend` Deployment·Service | +| `ingress.yaml` | `hyeonworks.com` 경로: `/api`·`/oauth2`·`/login`·`/logout` → backend, 나머지 → frontend | +| `network-policies.yaml` | namespace 안 기본 거부와 허용 여섯 | + +## 이미지와 실행 사용자 + +| 컨테이너 | 이미지 | pull | 사용자 | +| --- | --- | --- | --- | +| backend | `git.learn.hyeonworks.com/donghyeon.kang/tech-log-backend:46b1cc7` | `IfNotPresent` | uid 1000(이미지의 `app`), 권한 전부 버림 | +| frontend | `git.learn.hyeonworks.com/donghyeon.kang/tech-log-frontend:7a4e201` | `IfNotPresent` | root(nginx). `allowPrivilegeEscalation: false`만 | +| redis | `redis@sha256:c5d34a98…`(지금 운영이 쓰는 `redis:7-alpine`의 digest) | `IfNotPresent` | uid 999(이미지의 `redis`), 권한 전부 버림 | + +- 예전에는 `imagePullPolicy: Never`로 노드에 직접 넣은 이미지를 썼다. 2026-11-09 디스크 사고 때 + kubelet 이미지 GC가 그 이미지를 지웠고, 다시 받을 곳이 없어 운영이 내려갔다. 이제 Gitea 컨테이너 + 레지스트리에서 다시 받는다. +- 세 파드 모두 `priorityClassName: platform-critical`(platform-core `services/priority-classes`)이고 + seccomp는 `RuntimeDefault`다. +- **frontend non-root는 남은 일이다.** nginx 공식 이미지는 root로 시작해 80번을 열고 worker를 + `nginx`로 내린다. 권한을 버리거나 non-root로 돌리려면 이미지를 비특권 nginx(8080)로 바꾸고 Service + `targetPort`와 probe를 같이 바꿔야 한다. + +## 적용 + +전제(하나라도 없으면 적용하지 않는다): + +1. 두 이미지가 Gitea 레지스트리에 있다. 익명 pull이 되는지 노드에서 확인한다. + `sudo k3s crictl pull git.learn.hyeonworks.com/donghyeon.kang/tech-log-backend:46b1cc7` + (frontend도 같다). 미리 받아 두면 backend(Recreate)가 멈추는 시간이 짧아진다. +2. PriorityClass `platform-critical`이 있다: `kubectl get priorityclass platform-critical`. +3. Secret `hyeonworks-prod/hyeonworks-secrets`가 있다. + +```bash +curl -s -o /dev/null -w '%{http_code}\n' https://hyeonworks.com/ +kubectl diff -k deploy/production +kubectl apply -k deploy/production +kubectl -n hyeonworks-prod rollout status deploy/techlog-backend deploy/techlog-frontend deploy/redis +curl -s -o /dev/null -w '%{http_code}\n' https://hyeonworks.com/ +curl -s -o /dev/null -w '%{http_code}\n' https://hyeonworks.com/api/v1/public/home +``` + +- backend는 `Recreate`라 새 파드가 준비될 때까지 API가 멈춘다(1분 안팎). +- redis가 다시 시작되면 로그인 세션이 모두 풀린다. + +되돌리기: `kubectl -n hyeonworks-prod rollout undo deploy/<이름>`. 그 뒤 이 폴더를 되돌리는 커밋을 만든다. diff --git a/deploy/production/backend-deployment.yaml b/deploy/production/backend-deployment.yaml index dde0160..7b06333 100644 --- a/deploy/production/backend-deployment.yaml +++ b/deploy/production/backend-deployment.yaml @@ -122,8 +122,8 @@ spec: value: redis.hyeonworks-prod.svc.cluster.local:6379 - name: APP_TRACING_ENABLED value: 'true' - image: tech-log-backend:46b1cc7 - imagePullPolicy: Never + image: git.learn.hyeonworks.com/donghyeon.kang/tech-log-backend:46b1cc7 + imagePullPolicy: IfNotPresent livenessProbe: failureThreshold: 3 httpGet: @@ -167,12 +167,23 @@ spec: - mountPath: /etc/techlog-logging name: logging-config readOnly: true + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: + - ALL dnsPolicy: ClusterFirst restartPolicy: Always schedulerName: default-scheduler - securityContext: {} + securityContext: + runAsNonRoot: true + runAsUser: 1000 + runAsGroup: 1000 + seccompProfile: + type: RuntimeDefault terminationGracePeriodSeconds: 30 volumes: - configMap: name: techlog-logging name: logging-config + priorityClassName: platform-critical diff --git a/deploy/production/frontend-deployment.yaml b/deploy/production/frontend-deployment.yaml index 0848864..06aec0b 100644 --- a/deploy/production/frontend-deployment.yaml +++ b/deploy/production/frontend-deployment.yaml @@ -21,8 +21,8 @@ spec: spec: automountServiceAccountToken: false containers: - - image: docker.io/library/tech-log-frontend:7a4e201 - imagePullPolicy: Never + - image: git.learn.hyeonworks.com/donghyeon.kang/tech-log-frontend:7a4e201 + imagePullPolicy: IfNotPresent livenessProbe: failureThreshold: 3 httpGet: @@ -56,8 +56,13 @@ spec: memory: 32Mi terminationMessagePath: /dev/termination-log terminationMessagePolicy: File + securityContext: + allowPrivilegeEscalation: false dnsPolicy: ClusterFirst restartPolicy: Always schedulerName: default-scheduler - securityContext: {} + securityContext: + seccompProfile: + type: RuntimeDefault terminationGracePeriodSeconds: 30 + priorityClassName: platform-critical diff --git a/deploy/production/redis-deployment.yaml b/deploy/production/redis-deployment.yaml index 784c0c0..1fa9e28 100644 --- a/deploy/production/redis-deployment.yaml +++ b/deploy/production/redis-deployment.yaml @@ -24,7 +24,7 @@ spec: - '' - --appendonly - 'no' - image: redis:7-alpine + image: docker.io/library/redis@sha256:c5d34a98396a4775e223c74e929162c35c5a2182901ba26b50ade939941ce14b imagePullPolicy: IfNotPresent livenessProbe: exec: @@ -59,8 +59,19 @@ spec: memory: 64Mi terminationMessagePath: /dev/termination-log terminationMessagePolicy: File + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: + - ALL dnsPolicy: ClusterFirst restartPolicy: Always schedulerName: default-scheduler - securityContext: {} + securityContext: + runAsNonRoot: true + runAsUser: 999 + runAsGroup: 999 + seccompProfile: + type: RuntimeDefault terminationGracePeriodSeconds: 30 + priorityClassName: platform-critical