> ## Documentation Index
> Fetch the complete documentation index at: https://wb-21fd5541-feat-cli-docs-generator.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploy W&B Platform on GCP

> GCP에서 W&B 서버 호스팅하기.

<Note>
  Weights & Biases 에서는 [W\&B Multi-tenant Cloud](/ko/platform/hosting/hosting-options/multi_tenant_cloud) 또는 [W\&B Dedicated Cloud](/ko/platform/hosting/hosting-options/dedicated_cloud/) 배포 유형과 같은 완전 관리형 배포 옵션을 권장합니다. Weights & Biases 완전 관리형 서비스는 사용하기 간편하고 안전하며, 필요한 설정이 최소화되어 있습니다.
</Note>

W\&B Server를 자체 관리하기로 결정했다면, GCP에 플랫폼을 배포하기 위해 [W\&B Server GCP Terraform Module](https://registry.terraform.io/modules/wandb/wandb/google/latest)을 사용하는 것이 좋습니다.

모듈 문서는 광범위하며 사용 가능한 모든 옵션이 포함되어 있습니다.

시작하기 전에 Terraform에서 사용 가능한 [원격 백엔드](https://developer.hashicorp.com/terraform/language/backend/remote) 중 하나를 선택하여 [State File](https://developer.hashicorp.com/terraform/language/state)을 저장하는 것이 좋습니다.

State File은 모든 구성 요소를 다시 만들지 않고도 업그레이드를 롤아웃하거나 배포를 변경하는 데 필요한 리소스입니다.

Terraform Module은 다음과 같은 `필수` 구성 요소를 배포합니다.

* VPC
* Cloud SQL for MySQL
* Cloud Storage Bucket
* Google Kubernetes Engine
* KMS Crypto Key
* Load Balancer

다른 배포 옵션에는 다음과 같은 선택적 구성 요소가 포함될 수도 있습니다.

* Redis용 메모리 저장소
* Pub/Sub 메시지 시스템

## 사전 필수 권한

terraform을 실행할 계정은 사용된 GCP 프로젝트에서 `roles/owner` 역할을 가지고 있어야 합니다.

## 일반적인 단계

이 항목의 단계는 이 문서에서 다루는 모든 배포 옵션에 공통적입니다.

1. 개발 환경을 준비합니다.
   * [Terraform](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli)을 설치합니다.
   * 사용할 코드로 Git 저장소를 만드는 것이 좋지만, 파일을 로컬에 보관할 수도 있습니다.
   * [Google Cloud Console](https://console.cloud.google.com/)에서 프로젝트를 만듭니다.
   * GCP로 인증합니다 ([gcloud 설치](https://cloud.google.com/sdk/docs/install)되었는지 확인).
     `gcloud auth application-default login`

2. `terraform.tfvars` 파일을 만듭니다.

   `tvfars` 파일 내용은 설치 유형에 따라 사용자 정의할 수 있지만, 최소 권장 사항은 아래 예제와 같습니다.

   ```bash theme={null}
   project_id  = "wandb-project"
   region      = "europe-west2"
   zone        = "europe-west2-a"
   namespace   = "wandb"
   license     = "xxxxxxxxxxyyyyyyyyyyyzzzzzzz"
   subdomain   = "wandb-gcp"
   domain_name = "wandb.ml"
   ```

   여기에 정의된 변수는 배포 전에 결정해야 합니다. `namespace` 변수는 Terraform에서 생성된 모든 리소스의 접두사가 되는 문자열입니다.

   `subdomain`과 `domain`의 조합은 Weights & Biases가 구성될 FQDN을 형성합니다. 위의 예에서 Weights & Biases FQDN은 `wandb-gcp.wandb.ml`입니다.

3. `variables.tf` 파일을 만듭니다.

   `terraform.tfvars`에서 구성된 모든 옵션에 대해 Terraform은 해당 변수 선언이 필요합니다.

   ```
   variable "project_id" {
     type        = string
     description = "Project ID"
   }

   variable "region" {
     type        = string
     description = "Google region"
   }

   variable "zone" {
     type        = string
     description = "Google zone"
   }

   variable "namespace" {
     type        = string
     description = "리소스에 사용되는 네임스페이스 접두사"
   }

   variable "domain_name" {
     type        = string
     description = "Weights & Biases UI에 엑세스하기 위한 도메인 이름입니다."
   }

   variable "subdomain" {
     type        = string
     description = "Weights & Biases UI에 엑세스하기 위한 하위 도메인입니다."
   }

   variable "license" {
     type        = string
     description = "W&B License"
   }
   ```

## 배포 - 권장 (\~20분)

이는 모든 `필수` 구성 요소를 만들고 `Kubernetes Cluster`에 최신 버전의 `W&B`를 설치하는 가장 간단한 배포 옵션 구성입니다.

1. `main.tf`를 만듭니다.

   [일반적인 단계](#general-steps)에서 파일을 만든 동일한 디렉토리에 다음 내용으로 `main.tf` 파일을 만듭니다.

   ```
   provider "google" {
    project = var.project_id
    region  = var.region
    zone    = var.zone
   }

   provider "google-beta" {
    project = var.project_id
    region  = var.region
    zone    = var.zone
   }

   data "google_client_config" "current" {}

   provider "kubernetes" {
     host                   = "https://${module.wandb.cluster_endpoint}"
     cluster_ca_certificate = base64decode(module.wandb.cluster_ca_certificate)
     token                  = data.google_client_config.current.access_token
   }

   # Spin up all required services
   module "wandb" {
     source  = "wandb/wandb/google"
     version = "~> 5.0"

     namespace   = var.namespace
     license     = var.license
     domain_name = var.domain_name
     subdomain   = var.subdomain
   }

   # You'll want to update your DNS with the provisioned IP address
   output "url" {
     value = module.wandb.url
   }

   output "address" {
     value = module.wandb.address
   }

   output "bucket_name" {
     value = module.wandb.bucket_name
   }
   ```

2. W\&B를 배포합니다.

   W\&B를 배포하려면 다음 코맨드를 실행합니다.

   ```
   terraform init
   terraform apply -var-file=terraform.tfvars
   ```

## REDIS Cache를 사용한 배포

또 다른 배포 옵션은 `Redis`를 사용하여 SQL 쿼리를 캐시하고 Experiments에 대한 메트릭 로드 시 애플리케이션 응답 속도를 높이는 것입니다.

캐시를 활성화하려면 권장되는 [배포 옵션 섹션](#deployment---recommended-20-mins)에 지정된 동일한 `main.tf` 파일에 옵션 `create_redis = true`를 추가해야 합니다.

```
[...]

module "wandb" {
  source  = "wandb/wandb/google"
  version = "~> 1.0"

  namespace    = var.namespace
  license      = var.license
  domain_name  = var.domain_name
  subdomain    = var.subdomain
  allowed_inbound_cidrs = ["*"]
  #Enable Redis
  create_redis = true

}
[...]
```

## 외부 큐를 사용한 배포

배포 옵션 3은 외부 `message broker`를 활성화하는 것으로 구성됩니다. W\&B는 broker가 내장되어 있으므로 선택 사항입니다. 이 옵션은 성능 향상을 제공하지 않습니다.

메시지 broker를 제공하는 GCP 리소스는 `Pub/Sub`이며, 이를 활성화하려면 권장되는 [배포 옵션 섹션](#deployment---recommended-20-mins)에 지정된 동일한 `main.tf`에 옵션 `use_internal_queue = false`를 추가해야 합니다.

```
[...]

module "wandb" {
  source  = "wandb/wandb/google"
  version = "~> 1.0"

  namespace          = var.namespace
  license            = var.license
  domain_name        = var.domain_name
  subdomain          = var.subdomain
  allowed_inbound_cidrs = ["*"]
  #Create and use Pub/Sub
  use_internal_queue = false

}

[...]

```

## 기타 배포 옵션

동일한 파일에 모든 구성을 추가하여 세 가지 배포 옵션을 모두 결합할 수 있습니다.
[Terraform Module](https://github.com/wandb/terraform-google-wandb)은 `배포 - 권장`에서 찾은 표준 옵션 및 최소 구성과 함께 결합할 수 있는 여러 옵션을 제공합니다.

## 수동 구성

GCP Storage 버킷을 W\&B의 파일 스토리지 백엔드로 사용하려면 다음을 만들어야 합니다.

* [PubSub Topic 및 Subscription](#create-pubsub-topic-and-subscription)
* [Storage Bucket](#create-storage-bucket)
* [PubSub Notification](#create-pubsub-notification)

### PubSub Topic 및 Subscription 만들기

PubSub 토픽 및 구독을 만들려면 아래 절차를 따르십시오.

1. GCP Console 내에서 Pub/Sub 서비스로 이동합니다.
2. **토픽 만들기**를 선택하고 토픽 이름을 입력합니다.
3. 페이지 하단에서 **구독 만들기**를 선택합니다. **전달 유형**이 **Pull**로 설정되어 있는지 확인합니다.
4. **만들기**를 클릭합니다.

인스턴스를 실행하는 서비스 계정 또는 계정이 이 구독에 대해 `pubsub.admin` 역할을 가지고 있는지 확인합니다. 자세한 내용은 [https://cloud.google.com/pubsub/docs/access-control#console을](https://cloud.google.com/pubsub/docs/access-control#console을) 참조하십시오.

### Storage Bucket 만들기

1. **Cloud Storage Buckets** 페이지로 이동합니다.
2. **버킷 만들기**를 선택하고 버킷 이름을 입력합니다. **Standard** [스토리지 클래스](https://cloud.google.com/storage/docs/storage-classes)를 선택해야 합니다.

인스턴스를 실행하는 서비스 계정 또는 계정이 다음을 모두 가지고 있는지 확인합니다.

* 이전 단계에서 만든 버킷에 대한 엑세스 권한
* 이 버킷에 대한 `storage.objectAdmin` 역할 자세한 내용은 [https://cloud.google.com/storage/docs/access-control/using-iam-permissions#bucket-add를](https://cloud.google.com/storage/docs/access-control/using-iam-permissions#bucket-add를) 참조하십시오.

<Note>
  인스턴스는 서명된 파일 URL을 만들기 위해 GCP에서 `iam.serviceAccounts.signBlob` 권한도 필요합니다. 인스턴스가 실행되는 서비스 계정 또는 IAM 멤버에 `Service Account Token Creator` 역할을 추가하여 권한을 활성화합니다.
</Note>

3. CORS 엑세스를 활성화합니다. 이는 커맨드라인을 사용해서만 수행할 수 있습니다. 먼저 다음 CORS 구성으로 JSON 파일을 만듭니다.

```
cors:
- maxAgeSeconds: 3600
  method:
   - GET
   - PUT
     origin:
   - '<YOUR_W&B_SERVER_HOST>'
     responseHeader:
   - Content-Type
```

origin 값의 체계, 호스트 및 포트가 정확히 일치해야 합니다.

4. `gcloud`가 설치되어 있고 올바른 GCP 프로젝트에 로그인되어 있는지 확인합니다.
5. 다음을 실행합니다.

```bash theme={null}
gcloud storage buckets update gs://<BUCKET_NAME> --cors-file=<CORS_CONFIG_FILE>
```

### PubSub Notification 만들기

커맨드라인에서 아래 절차에 따라 Storage Bucket에서 Pub/Sub 토픽으로의 알림 스트림을 만듭니다.

<Note>
  CLI를 사용하여 알림 스트림을 만들어야 합니다. `gcloud`가 설치되어 있는지 확인합니다.
</Note>

1. GCP 프로젝트에 로그인합니다.
2. 터미널에서 다음을 실행합니다.

```bash theme={null}
gcloud pubsub topics list  # 참조용 토픽 이름 나열
gcloud storage ls          # 참조용 버킷 이름 나열

# 버킷 알림 만들기
gcloud storage buckets notifications create gs://<BUCKET_NAME> --topic=<TOPIC_NAME>
```

[자세한 참조는 Cloud Storage 웹사이트에서 확인할 수 있습니다.](https://cloud.google.com/storage/docs/reporting-changes)

### W\&B 서버 구성

1. 마지막으로 `http(s)://YOUR-W&B-SERVER-HOST/console/settings/system`에서 W\&B `System Connections` 페이지로 이동합니다.
2. `Google Cloud Storage (gcs)` 제공자를 선택합니다.
3. GCS 버킷 이름을 제공합니다.

<Frame>
  <img src="https://mintcdn.com/wb-21fd5541-feat-cli-docs-generator/z30ndE1lYRi8WMuv/images/hosting/configure_file_store_gcp.png?fit=max&auto=format&n=z30ndE1lYRi8WMuv&q=85&s=b29a72abbd7fa823b6024516d7ef352a" width="1752" height="878" data-path="images/hosting/configure_file_store_gcp.png" />
</Frame>

4. **설정 업데이트**를 눌러 새 설정을 적용합니다.

## W\&B Server 업그레이드

W\&B를 업데이트하려면 여기에 설명된 단계를 따르십시오.

1. `wandb_app` 모듈의 구성에 `wandb_version`을 추가합니다. 업그레이드할 W\&B 버전을 제공합니다. 예를 들어, 다음 줄은 W\&B 버전 `0.48.1`을 지정합니다.

```
module "wandb_app" {
    source  = "wandb/wandb/kubernetes"
    version = "~>5.0"

    license       = var.license
    wandb_version = "0.58.1"
```

<Note>
  또는 `wandb_version`을 `terraform.tfvars`에 추가하고 동일한 이름으로 변수를 만들고 리터럴 값 대신 `var.wandb_version`을 사용할 수 있습니다.
</Note>

2. 구성을 업데이트한 후 [배포 옵션 섹션](#deployment---recommended-20-mins)에 설명된 단계를 완료합니다.
