Google Cloud용 Gemini의 지원을 받아 GKE 클러스터를 만들고 수정하기

이 튜토리얼에서는 Google Cloud의 AI 기반 공동 작업 도구인 Google Cloud용 Gemini를 사용하여 Autopilot에서 Google Kubernetes Engine(GKE) 클러스터를 만들고 테스트하고 수정하는 방법을 보여줍니다. Gemini가 간단한 앱을 클러스터에 배포하고 앱의 일일 유지보수 기간을 만드는 데 어떤 도움을 주는지 보여줍니다. 이 튜토리얼은 숙련도에 상관없이 모든 엔지니어를 대상으로 합니다.

목표

  • Gemini 컨텍스트 기반 질문을 통해 GKE에 앱을 배포하는 데 사용할 수 있는 다양한 Google 서비스를 살펴봅니다.
  • Gemini에 프롬프트를 입력하여 기본 앱을 GKE 클러스터에 배포하는 데 사용할 수 있는 명령어를 제공받습니다.
  • Gemini를 사용하여 셸 명령어를 설명하고 생성하여 GKE 클러스터를 만들고 탐색하고 수정합니다.

사용된 Google Cloud 제품

이 튜토리얼에서는 비용이 청구될 수 있는 다음과 같은 Google Cloud 제품을 사용합니다. 가격 계산기를 사용하면 예상 사용량을 토대로 예상 비용을 산출할 수 있습니다.

  • GKE. GKE는 컨테이너화된 애플리케이션을 대규모로 배포 및 관리할 수 있는 관리형 Kubernetes 서비스입니다. 가격 정보는 GKE 가격 책정을 참조하세요.

  • Gemini. Gemini는 개발자, 데이터 과학자 등 다양한 사용자에게 생성형 AI 기반 지원을 제공하는 Google Cloud의 상시 공동 작업 도구입니다. 통합 지원 경험의 제공을 위해 Gemini는 많은 Google Cloud 제품에 포함되어 있습니다.

시작하기 전에

  1. GKE API를 사용 설정합니다.
  2. Gemini가 Google Cloud 사용자 계정과 프로젝트에 설정되어 있는지 확인합니다.

Google Cloud의 Kubernetes 살펴보기

다음 예시에서는 웹 애플리케이션을 개발하는 팀의 인프라 설정을 담당하는 인프라 관리자를 사용자로 가정합니다. 조직 전체적으로 컨테이너와 Kubernetes를 사용해 표준화했기 때문에 이 팀에서는 Google Cloud의 Kubernetes에서 웹 애플리케이션을 실행하는 방법을 이해해야 합니다. 또한 인프라 관리 오버헤드를 최소화하고자 합니다.

Google Cloud 콘솔에서 Gemini와 채팅하여 도움을 받을 수 있습니다. Gemini 창을 사용하여 어떤 도움이 필요한지 설명하는 질문 또는 문장을 프롬프트로 입력하면 Gemini가 응답을 반환합니다. Gemini는 프롬프트나 해당 응답을 데이터로 사용하여 모델을 학습시키지 않습니다. 자세한 내용은 Google Cloud용 Gemini에서 사용자 데이터를 사용하는 방법을 참조하세요.

적절한 응답을 생성하는 프롬프트를 작성하는 방법에 대한 자세한 내용은 보다 효과적인 Gemini 프롬프트 작성을 참조하세요.

Gemini에 프롬프트를 입력하여 Google Cloud에서 Kubernetes를 실행하는 방법을 결정하는 데 도움을 받으려면 다음 단계를 수행합니다.

  1. Google Cloud 콘솔 툴바에서 spark Gemini 열기를 클릭합니다.

  2. Gemini 창에서 요구사항 및 선호도에 따라 다음 프롬프트를 입력한 후 보내기를 클릭합니다.

    How can I run Kubernetes on Google Cloud without having to own
    management of nodes and the control plane?
    

    Gemini의 응답은 다음과 같이 표시될 수 있습니다.

    To run Kubernetes on Google Cloud without having to own management of
    nodes and the control plane, you can use Google Kubernetes Engine
    (Google Kubernetes Engine (GKE)) in Autopilot. In Autopilot mode, Google manages the
    control plane and system components for you, and also manages your
    worker nodes.
    
  3. 후속 질문을 입력합니다. 예를 들어 Terraform을 사용하여 Autopilot 모드의 GKE 클러스터 생성을 표준화하려면 다음 프롬프트를 입력합니다.

    Can you use Terraform to provision GKE clusters in Autopilot mode?
    

    Gemini의 응답은 다음과 같이 표시될 수 있습니다.

    Yes, you can use Terraform to provision GKE clusters in Autopilot
    mode. Terraform is a tool that can be used to create and manage
    infrastructure on Google Cloud Platform. Find more information
    for your question here:
    https://cloud.google.com/blog/products/containers-kubernetes/partner-devops-and-security-solutions-for-gke-autopilot
    
  4. 선택사항: 채팅 기록이 다음에 질문할 내용과 관련이 없으면 채팅 기록을 재설정합니다. Gemini 창에서 삭제 아이콘을 클릭한 후 채팅 재설정을 선택합니다.

Autopilot 모드로 GKE 클러스터 만들기

Autopilot 모드에서 GKE를 사용하여 Kubernetes를 실행하는 데 익숙하지 않다고 가정하겠습니다. 개발자를 위해 클러스터를 프로비저닝하기 전에 먼저 Autopilot 모드의 GKE를 테스트하기로 결정합니다. 이 섹션에서는 Gemini에 프롬프트를 입력하여 Autopilot 모드의 GKE 클러스터에서 테스트 웹 앱을 만들고 실행하는 데 도움을 받습니다.

  1. Gemini 창에서 다음 프롬프트를 입력한 후 보내기를 클릭합니다.

    How do I create a GKE Autopilot cluster?
    

    Gemini가 Google Cloud 콘솔과 Google Cloud CLI를 사용하여 클러스터를 만드는 방법을 응답으로 반환합니다.

  2. CLUSTER_NAME, REGION, PROJECT_ID와 같은 자리표시자 값이 포함된 응답이 표시되는 경우 프롬프트에 해당 정보를 추가하면 더욱 유용한 응답이 생성될 수 있습니다. 세부정보로 프롬프트를 미세 조정합니다.

    What is the command to create a GKE Autopilot cluster in my current
    project named gemini-demo in the us-central region using the gcloud CLI?
    

    Gemini는 다음과 비슷한 응답을 반환합니다.

    gcloud container clusters create-auto gemini-demo --region us-central1
    

    Gemini에서 제공하는 명령어를 사용하려면 Cloud Shell을 열고 응답에 있는 위의 gcloud 명령어를 실행합니다.

    몇 분 후 GKE Autopilot 클러스터를 사용할 수 있게 됩니다.

샘플 웹 애플리케이션 배포하기

이제 Autopilot 모드의 GKE 클러스터가 생성되었으므로 팀이 이 인프라에서 실행할 애플리케이션과 유사한 샘플 웹 애플리케이션의 실행을 테스트하려고 합니다. 내부적으로 컨테이너화된 웹 애플리케이션을 테스트하기 위해 북마크한 Google의 컨테이너 이미지 us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0이 표시됩니다.

  1. Gemini 창에서 다음 프롬프트를 입력한 후 보내기를 클릭합니다.

    What is the kubectl command to create a deployment called
    hello-server for the image us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0?
    

    Gemini는 다음과 비슷한 응답을 반환합니다.

    To create a deployment called hello-server for the image
    us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0, you
    can use the following kubectl command:
    
    kubectl create deployment hello-server --image=us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0
    

    Cloud Shell에서 위의 kubectl 명령어를 실행합니다.

  2. 웹 서버가 생성되었으므로 이제 웹 서버 앞에 부하 분산기를 프로비저닝하여 인터넷에 노출하는 과정을 테스트하기로 결정합니다.

    Gemini 창에서 다음 프롬프트를 입력한 후 보내기를 클릭합니다.

    What is the kubectl command to expose this deployment on port 80 with
    a load balancer?
    

    Gemini는 다음과 비슷한 응답을 반환합니다.

    To expose the hello-server deployment on port 80 with a load
    balancer, you can use the following kubectl expose command:
    
    kubectl expose deployment hello-server \
      --type LoadBalancer \
      --port 80 \
      --target-port 8080
    

    이 명령어를 실행하면 컨테이너의 Compute Engine 부하 분산기가 생성됩니다.

    컨텍스트를 더 제공하면 물론 도움이 되지만 Gemini가 프롬프트에 포함되지 않은 대화 기록에서 배포 이름 hello-server를 가져올 수 있었다는 사실을 알 수 있습니다.

  3. 이제 웹 서버가 실행 중이고 요청을 제대로 처리하는지 확인하려고 합니다. 배포된 애플리케이션을 확인하려면 자신이 만든 Kubernetes 서비스에서 외부 IP 주소를 가져와야 합니다.

    다음 프롬프트를 입력합니다.

    What is the kubectl command to see the external IP address
    associated with this load balancer?
    

    Gemini는 다음과 비슷한 응답을 반환합니다.

    To see the external IP associated with a load balancer, you can use
    the following kubectl command:
    
    kubectl get service hello-server -w
    
    This will output the name of the service, the type of service, the
    cluster IP address, the external IP address, and the ports that the
    service is listening on.
    

    몇 분 후 앞의 kubectl 명령어를 실행하면 다음과 비슷한 결과가 생성됩니다.

    NAME           TYPE           CLUSTER-IP      EXTERNAL-IP     PORT(S)        AGE
    hello-server   LoadBalancer   34.118.227.57   35.225.15.112   80:31473/TCP   6m18s
    

    이제 EXTERNAL-IP에 대해 반환된 값을 사용하여 GKE에서 실행되는 웹 애플리케이션에 액세스할 수 있습니다.

클러스터 업그레이드 전략 계획

Autopilot 모드의 GKE 클러스터에서 팀의 기본 사용 사례를 테스트했습니다. 하지만 팀에서 GKE Autopilot을 사용하도록 하기 전에 클러스터 유지보수 또는 업그레이드 시간을 구성하려고 합니다.

팀의 웹 애플리케이션 사용자들은 일일 트래픽 패턴을 보입니다. Gemini에서 GKE Autopilot이 자동으로 클러스터 유지보수를 처리한다고 알려줘 웹 애플리케이션에서 사용량이 가장 많은 시간을 피해 유지보수가 수행되도록 지시하려고 합니다.

  1. 다음 프롬프트를 입력합니다.

    How can I configure periods of time where GKE Autopilot won't
    perform maintenance or upgrades on my cluster nodes?
    

    Gemini는 다음과 비슷한 응답을 반환합니다.

    To configure periods of time where GKE Autopilot won't perform
    maintenance or upgrades on your cluster nodes, you can use
    maintenance windows and exclusions.
    
    Maintenance windows are periods of time when GKE Autopilot is allowed
    to perform maintenance and upgrades on your cluster nodes. You can
    specify a maintenance window for your cluster when you create it, or
    you can update an existing cluster to specify a maintenance
    window.
    
    Maintenance exclusions are periods of time when GKE Autopilot is not
    allowed to perform maintenance or upgrades on your cluster nodes. You
    can create a maintenance exclusion for your cluster when you create
    it, or you can update an existing cluster to create a maintenance
    exclusion.
    
    To create a maintenance window or a maintenance exclusion, you can
    use the Google Cloud console, the gcloud CLI, or the Kubernetes
    API.
    
  2. gcloud를 사용하여 웹 애플리케이션 사용 중지 시간 동안 일일 유지보수 기간을 만들기로 결정합니다. 다음 프롬프트를 입력합니다.

    How can I create a daily maintenance window from 22:00 to 02:00 using
    `gcloud` for my GKE Autopilot cluster named gemini-demo?
    

    Gemini는 다음과 비슷한 응답을 반환합니다.

    To create a daily maintenance window using gcloud CLI for your
    gemini-demo GKE Autopilot cluster that goes from 22:00 to 02:00, you
    can use the following command:
    
    gcloud container clusters update gemini-demo \
      --maintenance-window-start 22:00 \
      --maintenance-window-end 02:00 \
      --maintenance-window-recurrence "FREQ=DAILY"
    
    This command will create a daily maintenance window that runs from
    22:00 to 02:00 UTC time zone.
    

    이 명령어를 실행하면 팀에 프로비저닝한 인프라가 사용자의 사용량이 가장 적은 시간에 유지보수를 수행합니다. 이제 웹 애플리케이션팀에 GKE Autopilot을 추천하면 됩니다.

삭제

이 튜토리얼에서 사용한 리소스 비용이 Google Cloud 계정에 청구되지 않도록 하려면 이 튜토리얼에서 만든 Google Cloud 프로젝트를 삭제하면 됩니다. 또는 개별 리소스를 삭제할 수 있습니다.

  1. Google Cloud 콘솔에서 리소스 관리 페이지로 이동합니다.

    리소스 관리로 이동

  2. 프로젝트 목록에서 삭제할 프로젝트를 선택하고 삭제를 클릭합니다.
  3. 대화상자에서 프로젝트 ID를 입력한 후 종료를 클릭하여 프로젝트를 삭제합니다.

다음 단계