본문으로 건너뛰기

Kubernetes 배포 ​

배포 전 준비 ​

  • 사용 가능한 StorageClass 또는 PVC와 연결할 수 있도록 미리 준비한 PV가 필요합니다.
  • PostgreSQL과 Redis의 연결 주소 및 인증 정보를 준비합니다. 아래에서는 PostgreSQL 17과 Redis 7을 사용하며 데이터베이스 계정에는 스키마 마이그레이션 권한이 필요합니다.

네임스페이스와 설치 토큰 만들기 ​

설치 토큰을 Secret으로 전달하면 설치 도중 Pod가 재시작해도 같은 토큰을 사용합니다.

sh
kubectl create namespace sayrud
umask 077
openssl rand -hex 24 > sayrud-setup-token
kubectl -n sayrud create secret generic sayrud-setup --from-file=token=sayrud-setup-token

로컬의 sayrud-setup-token 파일을 보관했다가 설치 페이지에 입력하세요. SAYRUD_SETUP_TOKEN을 설정하면 프로그램은 토큰 값을 로그에 출력하지 않습니다.

애플리케이션 리소스 만들기 ​

다음 내용을 sayrud.yaml로 저장합니다. 기본 StorageClass를 사용하므로 클러스터에 기본 클래스가 없다면 두 PVC의 spec에 실제 storageClassName을 지정하세요.

yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: sayrud-config
  namespace: sayrud
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: sayrud-data
  namespace: sayrud
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: sayrud
  namespace: sayrud
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: sayrud
  template:
    metadata:
      labels:
        app: sayrud
    spec:
      terminationGracePeriodSeconds: 45
      securityContext:
        runAsNonRoot: true
        runAsUser: 10001
        runAsGroup: 10001
        fsGroup: 10001
        fsGroupChangePolicy: OnRootMismatch
      containers:
        - name: sayrud
          image: ghcr.io/sayrud/sayrud:latest
          imagePullPolicy: IfNotPresent
          args: ["web", "--port", "2830", "--config", "/home/app/config/sayrud.yaml"]
          env:
            - name: SAYRUD_SETUP_TOKEN
              valueFrom:
                secretKeyRef:
                  name: sayrud-setup
                  key: token
          ports:
            - name: http
              containerPort: 2830
          volumeMounts:
            - name: config
              mountPath: /home/app/config
            - name: data
              mountPath: /home/app/data
          startupProbe:
            httpGet:
              path: /-/healthz
              port: http
            periodSeconds: 5
            timeoutSeconds: 3
            failureThreshold: 60
          readinessProbe:
            httpGet:
              path: /-/readyz
              port: http
            periodSeconds: 5
            timeoutSeconds: 5
          livenessProbe:
            httpGet:
              path: /-/healthz
              port: http
            periodSeconds: 10
            timeoutSeconds: 3
          resources:
            requests:
              cpu: 100m
              memory: 256Mi
            limits:
              cpu: "1"
              memory: 1Gi
      volumes:
        - name: config
          persistentVolumeClaim:
            claimName: sayrud-config
        - name: data
          persistentVolumeClaim:
            claimName: sayrud-data
---
apiVersion: v1
kind: Service
metadata:
  name: sayrud
  namespace: sayrud
spec:
  selector:
    app: sayrud
  ports:
    - name: http
      port: 2830
      targetPort: http
  type: ClusterIP

설정 디렉터리는 쓰기 가능한 PVC에 마운트되어 설치 마법사가 파일을 만들 수 있습니다.

배포 후 상태를 확인합니다.

sh
kubectl apply -f sayrud.yaml
kubectl -n sayrud rollout status deployment/sayrud --timeout=300s
kubectl -n sayrud get pods,pvc
kubectl -n sayrud logs deployment/sayrud --tail=100

웹 설치 완료 ​

로컬 컴퓨터에서 포트를 전달하고 명령을 계속 실행해 둡니다.

sh
kubectl -n sayrud port-forward service/sayrud 2830:2830

http://localhost:2830/setup을 열고 로컬 sayrud-setup-token 파일의 토큰을 입력한 다음 웹 설치 절차에 따라 연결 설정과 관리자 생성을 완료합니다.

설치 후 설정은 sayrud-config PVC에, 첨부 파일은 sayrud-data PVC에 저장됩니다.

도메인으로 접근하려면 클러스터의 기존 Ingress 또는 게이트웨이를 sayrud:2830에 연결하고 HTTPS와 WebSocket 지원을 활성화하세요.

업그레이드 ​

데이터베이스, 설정, 업로드 파일을 백업하고 매니페스트의 이미지 버전을 변경한 뒤 실행합니다.

sh
kubectl apply -f sayrud.yaml
kubectl -n sayrud rollout status deployment/sayrud --timeout=300s
kubectl -n sayrud logs deployment/sayrud --tail=100

여러 복제본으로 배포 ​

설치를 한 번 완료한 뒤 확장에 필요한 공유 리소스를 준비합니다.

  • 모든 복제본을 같은 PostgreSQL 데이터베이스와 Redis 인스턴스에 연결합니다.
  • 같은 설정을 배포하고 특히 auth.secret_key를 동일하게 유지합니다. 생성된 설정은 Kubernetes Secret으로 마운트할 수 있으며 정상 실행 시에는 읽기 전용이어도 됩니다. 설정을 변경하면 Pod를 재시작하세요.
  • 첨부 파일은 S3, ReadWriteMany 볼륨 등의 공유 스토리지에 저장하고 기존 로컬 파일은 먼저 이전합니다.