> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ale.run/llms.txt
> Use this file to discover all available pages before exploring further.

# 準備事項

> GKEクラスターにaleをインストールするための準備事項です。

<Info>
  **案内**

  * このガイドは**Kubernetes v1.30**を基準に作成されました。
</Info>

***

## ツールのインストール

<Warning>
  Windowsの場合はWSL2をインストールし、Linux環境でaleを利用することをお勧めします。
  [こちら](https://learn.microsoft.com/ja-jp/windows/wsl/install)を参照してWSL2を先にインストールしてください。
</Warning>

<AccordionGroup>
  <Accordion title="gcloud CLI">
    以下のコマンドを入力してgcloud CLIをインストールし、シェルを再起動してください。

    ```bash theme={null}
    curl https://sdk.cloud.google.com | bash
    exec -l $SHELL
    ```

    以下のコマンドを入力して`gke-gcloud-auth-plugin`をインストールします。

    ```bash theme={null}
    gcloud components install gke-gcloud-auth-plugin
    ```
  </Accordion>

  <Accordion title="kubectl">
    使用しているOSおよびアーキテクチャに合わせてkubectlをインストールします。

    **macOS**

    <CodeGroup>
      ```bash macOS(Apple Silicon) theme={null}
      curl -LO "https://dl.k8s.io/release/v1.30.2/bin/darwin/arm64/kubectl"
      ```

      ```bash macOS(Intel) theme={null}
      curl -LO "https://dl.k8s.io/release/v1.30.2/bin/darwin/amd64/kubectl"
      ```
    </CodeGroup>

    **Linux**

    <CodeGroup>
      ```bash Linux(x86-64) theme={null}
      curl -LO https://dl.k8s.io/release/v1.30.2/bin/linux/amd64/kubectl
      ```

      ```bash Linux(arm64) theme={null}
      curl -LO https://dl.k8s.io/release/v1.30.2/bin/linux/arm64/kubectl
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="helm">
    ```bash theme={null}
    curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
    chmod 700 get_helm.sh
    ./get_helm.sh  
    ```
  </Accordion>
</AccordionGroup>

***

## Google Cloudアカウントの設定

### gcloud CLIの初期化

<Steps>
  <Step title="使用するGoogleアカウントとRegion、Zoneを登録するには以下のコマンドを実行します。">
    ```bash theme={null}
    gcloud init
    ```
  </Step>

  <Step title="プロンプトで`Sign in with a new Google Account`に該当する数値を入力してGoogleアカウントにログインします。既にログイン済みのアカウントを使用する場合は、その数値を入力します。">
    ```bash theme={null}
      Choose the account you want to use for this configuration.
      To use a federated user account, exit this command and sign in to the gcloud CLI with your login configuration file, then run this command again.

      Select an account:
        [1] Sign in with a new Google Account
        [2] Skip this step
      Please enter your numeric choice: 
    ```
  </Step>

  <Step title="Google Cloudはプロジェクト単位でリソースを割り当てて使用します。`Create a new project`に該当する数値を入力して新しいプロジェクトを作成できます。既に作成されたプロジェクトを使用する場合は、該当する数値を入力してください。">
    ```bash theme={null}
    Pick cloud project to use:
     [1] Enter a project ID
     [2] Create a new project
    Please enter numeric choice or text value (must exactly match list item):  
    ```
  </Step>

  <Step title="RegionおよびZoneのデフォルト値を設定するかどうかを尋ねるプロンプトで`y`を入力し、デフォルト値に設定するRegion/Zoneに該当する数値を入力してください。">
    ```bash theme={null}
    Do you want to configure a default Compute Region and Zone? (Y/n)?   y

    Which Google Compute Engine zone would you like to use as project default?
    If you do not specify a zone via a command line flag while working with Compute Engine resources, the default is assumed.
     [1] us-east1-b
     [2] us-east1-c
     [3] us-east1-d
     [4] us-east4-c
     [5] us-east4-b
     [6] us-east4-a
     [7] us-central1-c
     [8] us-central1-a
     [9] us-central1-f
     [10] us-central1-b
     [11] us-west1-b
     [12] us-west1-c
     [13] us-west1-a
    ...
    Did not print [75] options.
    Too many options [125]. Enter "list" at prompt to print choices fully.
    Please enter numeric choice or text value (must exactly match list item):
    ```

    <Info>
      以下のように表示されれば、正常に処理されたことを示します。

      ```bash theme={null}
      ...
      The Google Cloud CLI is configured and ready to use!

      * Commands that require authentication will use ale@example.com by default
      * Commands will reference project `ale` by default
      * Compute Engine commands will use region `asia-northeast3` by default
      * Compute Engine commands will use zone `asia-northeast3-a` by default
      ...
      ```
    </Info>
  </Step>
</Steps>

### 環境変数の登録

> 上記で作成したプロジェクトID、Region、クラスター名、ノードの配置Zoneを環境変数として登録します。

```bash theme={null}
export GCP_PROJECT_ID=<GCPプロジェクトID>
export GCP_REGION=<GCPリージョン>
export NODE_LOCATIONS=<クラスタノードの配置Zone> 
export CLUSTER_NAME=<作成するGKEクラスタ名>
```

### アカウントとプロジェクトの設定

<Steps>
  <Step title="以下のコマンドを入力してGoogleアカウントにログインしてください。">
    ```bash theme={null}
    gcloud auth login
    ```

    <Info>
      自動的にブラウザが起動し、Googleアカウントログイン用のページが表示されます。ブラウザでログインを完了すると、ターミナルでログインが完了したというメッセージを確認できます。
    </Info>
  </Step>

  <Step title="次にプロジェクトを設定するため、以下のコマンドを実行します。">
    ```bash theme={null}
    gcloud config set project $GCP_PROJECT_ID
    ```
  </Step>
</Steps>
