Terraform을 사용하여 Compute Engine VM에서 베어메탈 하이브리드 클러스터용 Google Distributed Cloud Virtual 만들기

이 문서에서는 고가용성(HA) 모드로 베어메탈용 GKE를 설치하고 사용해 볼 수 있도록 Terraform을 사용하여 Compute Engine에서 VM을 설정하는 방법을 설명합니다. 이를 위해 Google Cloud CLI를 사용하는 방법은 Compute Engine VM에서 베어메탈용 GKE 사용을 참조하세요.

하드웨어를 준비하지 않아도 베어메탈용 GKE를 빠르게 사용해 볼 수 있습니다. 제공된 Terraform 스크립트는 베어메탈용 GKE를 실행하는 데 사용할 수 있도록 Compute Engine에서 VM 네트워크를 만듭니다. 이 튜토리얼에서는 하이브리드 클러스터 배포 모델을 사용합니다.

샘플 클러스터를 실행하기 위해 다음 단계를 완료합니다.

  1. Terraform 스크립트를 실행하여 Compute Engine에서 VM 네트워크 설정
  2. 하이브리드 클러스터 배포
  3. 클러스터 확인

시작하기 전에

배포에는 다음 리소스가 필요합니다.

Compute Engine에서 VM 네트워크 설정

이 섹션에서는 anthos-samples 저장소의 Terraform 스크립트를 사용합니다. 이 스크립트는 Compute Engine을 다음 리소스로 구성합니다.

  • 하이브리드 클러스터를 배포하기 위한 6개 VM:
    • 하이브리드 클러스터를 다른 머신에 배포하기 위해 사용되는 하나의 관리자 VM
    • 하이브리드 클러스터 제어 영역을 실행하기 위해 필요한 3개의 제어 영역 노드에 대한 3개 VM
    • 하이브리드 클러스터에서 워크로드를 실행하기 위해 필요한 2개의 워커 노드에 대한 2개 VM
  • L2 연결을 에뮬레이션하기 위한 모든 노드 사이의 VxLAN 오버레이 네트워크
  • 관리자 VM에서 제어 영역워커 노드에 대한 SSH 액세스

Google Cloud에서 Compute Engine VM을 사용하는 베어메탈 인프라

instance_count Terraform 변수에 새 노드 이름을 추가하여 클러스터에서 노드 수를 변경할 수 있습니다.

###################################################################################
# The recommended instance count for High Availability (HA) is 3 for Control plane
# and 2 for Worker nodes.
###################################################################################
variable "instance_count" {
  description = "Number of instances to provision per layer (Control plane and Worker nodes) of the cluster"
  type        = map(any)
  default = {
    "controlplane" : 3
    "worker" : 2
  }
}

  1. anthos-bm-gcp-terraform 샘플을 위한 Terraform 스크립트 다운로드:

    git clone https://github.com/GoogleCloudPlatform/anthos-samples
    cd anthos-samples/anthos-bm-gcp-terraform
    
  2. 사용자 환경에 맞는 변수를 포함하도록 terraform.tfvars.sample 파일을 업데이트합니다.

    project_id       = "PROJECT_ID"
    region           = "GOOGLE_CLOUD_REGION"
    zone             = "GOOGLE_CLOUD_ZONE"
    credentials_file = "PATH_TO_GOOGLE_CLOUD_SERVICE_ACCOUNT_KEY_FILE"
    
  3. terraform.tfvars.sample 파일을 변수 파일에 대해 Terraform에서 사용되는 기본 이름으로 바꿉니다.

    mv terraform.tfvars.sample terraform.tfvars
    
  4. 샘플 디렉터리를 Terraform 작업 디렉터리로 초기화합니다. 이렇게 하면 git init와 비슷하게 필요한 Terraform 상태 관리 구성이 설정됩니다.

    terraform init
    
  5. Terraform 실행 계획을 만듭니다. 이 단계에서는 리소스 상태를 비교하고, 스크립트를 확인하고, 실행 계획을 만듭니다.

    terraform plan
    
  6. Terraform 스크립트에 설명된 변경 사항을 적용합니다. 이 단계에서는 원하는 리소스 상태에 도달하기 위해 제공된 제공업체(여기에서는 Google Cloud)에서 계획을 실행합니다.

    terraform apply  # when prompted to confirm the Terraform plan, type 'Yes' and enter
    

하이브리드 클러스터 배포

Terraform 실행이 완료되면 하이브리드 클러스터를 배포할 수 있습니다.

  1. SSH를 사용하여 관리자 호스트에 연결합니다.

    gcloud compute ssh tfadmin@cluster1-abm-ws0-001 --project=PROJECT_ID --zone=GOOGLE_CLOUD_ZONE
    

    VM 업데이트에 대한 메시지를 무시하고 이 튜토리얼을 완료하면 됩니다. VM을 테스트 환경으로 유지하려는 경우 Ubuntu 문서에 설명된 대로 OS를 업데이트하거나 다음 버전으로 업그레이드해야 할 수 있습니다.

  2. 다음 코드 블록을 실행하여 구성된 Compute Engine VM에서 cluster1 하이브리드 클러스터를 만듭니다.

    sudo ./run_initialization_checks.sh && \
    sudo bmctl create config -c cluster1 && \
    sudo cp ~/cluster1.yaml bmctl-workspace/cluster1 && \
    sudo bmctl create cluster -c cluster1
    

bmctl 명령어를 실행하면 새 하이브리드 클러스터 설정이 시작됩니다. 여기에는 노트에 대한 실행 전 검사 수행, 관리자 및 사용자 클러스터 만들기, Connect를 사용하여 Google Cloud에 클러스터 등록이 포함됩니다. 전체 설정은 최대 15분까지 걸릴 수 있습니다. 클러스터를 만드는 동안 다음 출력이 표시됩니다.

    Created config: bmctl-workspace/cluster1/cluster1.yaml
    Creating bootstrap cluster... OK
    Installing dependency components... OK
    Waiting for preflight check job to finish... OK
    - Validation Category: machines and network
            - [PASSED] 10.200.0.3
            - [PASSED] 10.200.0.4
            - [PASSED] 10.200.0.5
            - [PASSED] 10.200.0.6
            - [PASSED] 10.200.0.7
            - [PASSED] gcp
            - [PASSED] node-network
    Flushing logs... OK
    Applying resources for new cluster
    Waiting for cluster to become ready OK
    Writing kubeconfig file
    kubeconfig of created cluster is at bmctl-workspace/cluster1/cluster1-kubeconfig, please run
    kubectl --kubeconfig bmctl-workspace/cluster1/cluster1-kubeconfig get nodes
    to get cluster node status.
    Please restrict access to this file as it contains authentication credentials of your cluster.
    Waiting for node pools to become ready OK
    Moving admin cluster resources to the created admin cluster
    Flushing logs... OK
    Deleting bootstrap cluster... OK

클러스터 확인 및 상호작용

bmctl-workspace 디렉터리의 관리 머신에서 클러스터의 kubeconfig 파일을 찾을 수 있습니다. 배포를 확인하려면 다음 단계를 완료하세요.

  1. 관리자 호스트에서 연결이 끊어진 경우 SSH를 사용하여 호스트에 연결합니다.

    # You can copy the command from the output of the Terraform execution above
    gcloud compute ssh tfadmin@cluster1-abm-ws0-001 --project=PROJECT_ID --zone=GOOGLE_CLOUD_ZONE
    
  2. 클러스터에서 kubectl 명령어를 실행하려면 클러스터 구성 파일의 경로로 KUBECONFIG 환경 변수를 설정합니다.

    export CLUSTER_ID=cluster1
    export KUBECONFIG=$HOME/bmctl-workspace/$CLUSTER_ID/$CLUSTER_ID-kubeconfig
    kubectl get nodes
    

    다음 출력과 비슷하게 출력된 클러스터 노드가 표시됩니다.

    NAME          STATUS   ROLES    AGE   VERSION
    cluster1-abm-cp1-001   Ready    master   17m   v1.18.6-gke.6600
    cluster1-abm-cp2-001   Ready    master   16m   v1.18.6-gke.6600
    cluster1-abm-cp3-001   Ready    master   16m   v1.18.6-gke.6600
    cluster1-abm-w1-001    Ready    <none>   14m   v1.18.6-gke.6600
    cluster1-abm-w2-001    Ready    <none>   14m   v1.18.6-gke.6600
    

Google Cloud console에서 클러스터에 로그인

Google Cloud console에서 워크로드를 관측하려면 클러스터에 로그인해야 합니다.

클러스터에 로그인하는 방법에 대한 안내 및 자세한 내용은 Google Cloud console에서 클러스터에 로그인을 참조하세요.

삭제

클러스터 설정은 두 가지 방법으로 삭제할 수 있습니다.

Console

Terraform

  • Terraform에서 만든 모든 리소스를 삭제하기 전에 클러스터를 등록 취소합니다.
# Use SSH to connect to the admin host
gcloud compute ssh tfadmin@cluster1-abm-ws0-001 --project=PROJECT_ID --zone=GOOGLE_CLOUD_ZONE

# Reset the cluster
export CLUSTER_ID=cluster1
export KUBECONFIG=$HOME/bmctl-workspace/$CLUSTER_ID/$CLUSTER_ID-kubeconfig
sudo bmctl reset --cluster $CLUSTER_ID

# log out of the admin host
exit
  • Terraform을 사용하여 모든 리소스를 삭제합니다.
terraform destroy --auto-approve