Google Cloud용 Gemini 지원을 위한 비공개 빌드 만들기

이 튜토리얼에서는 Google Cloud의 AI 기반 공동 작업 도구인 Google Cloud용 Gemini를 사용하여 로그를 탐색하고 Google Kubernetes Engine에서 일련의 마이크로서비스를 위한 빌드 환경을 설정하는 방법을 보여줍니다.

이 튜토리얼은 숙련도에 상관없이 모든 DevOps 엔지니어를 대상으로 합니다.

목표

  • 포드의 로그를 관찰할 수 있도록 Gemini에 로깅 쿼리 프롬프트를 표시합니다.
  • 컨텍스트 기반 질문을 Gemini에 프롬프트로 입력하여 비공개 빌드 환경을 설정하는 방법을 이해합니다.
  • Gemini를 사용하여 컨테이너 이미지를 비공개로 안전하게 저장하는 방법을 알아봅니다.

사용된 Google Cloud 제품

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

  • Google Kubernetes Engine(GKE). GKE는 컨테이너화된 애플리케이션을 대규모로 배포 및 관리할 수 있는 관리형 Kubernetes 서비스입니다.

  • Cloud Logging. Logging은 스토리지, 검색, 분석, 모니터링을 지원하는 실시간 로그 관리 시스템입니다.

  • Cloud Build. Cloud Build는 Google Cloud 인프라에서 빌드를 실행하는 서비스입니다. Cloud Build를 사용해 다양한 저장소 또는 Cloud Storage 공간에서 소스 코드를 가져오고, 사양에 맞게 빌드를 실행하며, Docker 컨테이너 또는 Java 보관 파일과 같은 아티팩트를 생성할 수 있습니다.

  • Artifact Registry Artifact Registry로 컨테이너 이미지와 언어 패키지를 한곳에서 관리할 수 있습니다. 이를 통해 통합된 Google Cloud 환경의 일부로 아티팩트를 중앙에 저장하고 종속 항목을 빌드할 수 있습니다.

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

시작하기 전에

  1. Gemini가 Google Cloud 사용자 계정과 프로젝트에 설정되어 있는지 확인합니다. 또한 원하는 IDE에 Cloud Code 플러그인을 설치했는지 확인합니다. Cloud Shell 편집기 또는 Cloud Workstations를 IDE로 사용하려는 경우 Cloud Code 및 Gemini Code Assist를 기본적으로 사용할 수 있습니다.
  2. Google Kubernetes Engine API 사용 설정

    API 사용 설정

  3. Google Cloud 콘솔에서 Cloud Shell을 활성화합니다.

    Cloud Shell 활성화

    Google Cloud 콘솔 하단에서 Cloud Shell 세션이 시작되고 명령줄 프롬프트가 표시됩니다. Cloud Shell은 Google Cloud CLI가 사전 설치된 셸 환경으로, 현재 프로젝트의 값이 이미 설정되어 있습니다. 세션이 초기화되는 데 몇 초 정도 걸릴 수 있습니다.

  4. gcloud container clusters create 명령어를 사용하여 GKE 클러스터를 만듭니다.

    gcloud container clusters create test --region us-central1
    

    명령어를 실행하는 데 몇 분 정도 걸립니다. 출력은 다음과 비슷합니다.

    Creating cluster test in us-central1... Cluster is being health-checked (master is healthy)...done.
    
    Created https://container.googleapis.com/v1/projects/agmsb-gke-lab/zones/us-central1/clusters/test.
    
    To inspect the contents of your cluster, go to: https://console.cloud.google.com/kubernetes/workload_/gcloud/us-central1/test?project=agmsb-gke-lab
    kubeconfig entry generated for test.
    
    NAME: test
    LOCATION: us-central1
    MASTER_VERSION: 1.27.3-gke.100
    MASTER_IP: 34.72.99.149
    MACHINE_TYPE: e2-medium
    NODE_VERSION: 1.27.3-gke.100
    NUM_NODES: 9
    STATUS: RUNNING
    
  5. 저장소를 클론하고 kubectl을 사용하여 전자상거래 웹 앱을 구성하는 마이크로서비스 집합을 GKE 클러스터에 배포합니다.

    git clone https://github.com/GoogleCloudPlatform/microservices-demo && cd microservices-demo
    
    kubectl apply -f ./release/kubernetes-manifests.yaml
    
  6. 몇 분 후 브라우저에서 웹 앱에 액세스할 수 있도록 외부 IP 주소를 가져옵니다.

    kubectl get service frontend-external | awk '{print $4}'
    

GKE의 워크로드 로그 이해

다음 예시에서는 사용자가 GKE 클러스터에서 실행 중인 기존 마이크로서비스 집합을 상속하는 업무를 담당하는 DevOps 엔지니어라고 가정해 보겠습니다. 사용자는 환경을 이해하기 위해 다양한 마이크로서비스의 로그를 검사하기로 결정합니다.

선호하는 Code Assist 통합 IDE에서 Gemini와 채팅을 통해 도움을 받을 수 있습니다. Gemini 창을 사용하여 어떤 도움이 필요한지 설명하는 질문 또는 문장을 프롬프트로 입력하면 Gemini가 응답을 반환합니다.

Gemini는 프롬프트나 해당 응답을 데이터로 사용하여 모델을 학습시키지 않습니다. 자세한 내용은 Google Cloud용 Gemini에서 데이터를 사용하는 방법을 참조하세요.

마이크로서비스가 default 네임스페이스에 배포되었음을 알고 있습니다. 로그를 검사하는 데 도움이 되도록 Gemini에 프롬프트를 입력하려면 다음 단계를 따르세요.

  1. IDE의 작업 표시줄에서 chat_spark Gemini Code Assist를 클릭하여 Gemini Code Assist 창을 엽니다.

  2. Gemini Code Assist 창에 다음 프롬프트를 입력합니다.

    How can I write a Cloud Logging query to search for logs from Pods in
    a namespace called "default" in a Google Kubernetes Engine cluster named "test"?
    

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

    To write a Cloud Logging query to search for logs from Pods in a
    namespace called "default" in GKE cluster called "test", you
    can use the following query:
    
    resource.type="k8s_container"
    resource.labels.namespace_name="default"
    resource.labels.cluster_name="test"
    
    This query will search for all logs from Pods in the "default"
    namespace in the "test" GKE cluster. You can also use the
    Cloud Logging console to search for logs from Pods in a specific
    namespace and cluster. To do this, follow these steps:
    
    1. Go to the Cloud Logging console.
    2. In the Query builder pane, click
       Resource.
    3. In the Resource type list, select Kubernetes
       Container.
    4. In the Namespace name field, enter default.
    5. In the Cluster name field, enter test.
    6. Click Add.
    7. In the Query results pane, you will see a list of logs
       from Pods in the "default" namespace in the "test" GKE
       cluster.
    
  3. 이러한 로그를 검사하려면 쿼리에서 반환된 각 로그를 클릭합니다. 개별 로그에서 이 쿼리 설명을 클릭하면 응답은 다음과 비슷합니다.

    Sure. Here are the bullet points that explain the log entry:
    
    • The log entry is about a GET request to the /_healthz path.
    • The request was successful and returned a 200 status code.
    • The request took 0 milliseconds to complete.
    • The request was made by the x-liveness-probe session.
    • The request was made from the frontend-755cdc7957-pv8x5 pod
      in the default namespace.
    

컨테이너 이미지용 비공개 빌드 환경 만들기

로그를 관찰하여 워크로드에 대해 더 깊이 이해했으므로 이제 인프라를 설정하고 비공개 작업자 집합에 팀의 향후 컨테이너 이미지를 빌드하기로 결정합니다. 이 섹션에서는 Gemini에 프롬프트를 입력하여 빌드를 Google Cloud 프로젝트로 마이그레이션할 수 있도록 빌드 환경을 실행하는 방법을 이해하는 데 도움을 받습니다.

  1. IDE의 작업 표시줄에서 chat_spark Gemini Code Assist를 클릭하여 Gemini Code Assist 창을 엽니다.

  2. Gemini Code Assist 창에 다음 프롬프트를 입력합니다.

    How can I build a private build environment that is not connected to
    the internet in Google Cloud? I want to be able to use Docker to
    build my container images in this environment.
    

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

    To build a private build environment that is not connected to the internet
    in Google Cloud, you can use a Cloud Build private pool. A private pool
    is a group of build workers that are not connected to the public internet.
    You can create a private pool in a Virtual Private Cloud (VPC) network,
    which provides an additional layer of security for your build environment.
    
    To create a private pool, you will need to:
    
    1. Create a VPC network.
    2. Create a private pool in the VPC network.
    3. Configure your build config file to use the private pool.
    
    Once you have created a private pool, you can use it to build your
    container images using Docker. To do this, you will need to:
    
    1. Create a Dockerfile.
    2. Create a build config file.
    3. Run the `gcloud builds submit` command.
    
    The `gcloud builds submit` command will build your container image
    using the private pool.
    
    Find more information for your question here:
    
    • https://cloud.google.com/build/docs/private-pools/create-manage-private-pools
    
  3. Cloud Build 비공개 풀이 실행 가능한 것처럼 보이기 때문에 첫 번째 비공개 풀을 만드는 데 Gemini의 지원을 요청합니다. 다음 프롬프트를 입력합니다.

    Can you give me a gcloud command to create my first Cloud Build
    private worker pool?
    

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

    Here's how you can create your first private worker pool using the gcloud
    command:
    
    1. Define your pool configuration:
    
    First, you need to define the configuration of your private pool. This
    includes details like the pool name, region, machine type, disk size, and
    network settings. You can do this by creating a JSON file named
    workerpool.json with the following structure:
    
    {
      "name": "my-first-privatepool",
      "location": "us-central1",
      "machineType": "e2-standard-2",
      "diskSizeGb": 800,
      "network": "projects/your-project-id/global/networks/default",
      "assignExternalIP": true
    }
    
    2. Create the pool using gcloud:
    
    Once you have the configuration file ready, you can use the following gcloud
    command to create the private worker pool:
    
    gcloud builds worker-pools create \
      --project=gsm-project-382212 \
      --location=us-central1 \
      --worker-pool-id=my-first-privatepool \
      --file=workerpool.json
    
    Explanation of the command:
    
    - gcloud builds worker-pools create : This is the command to create a new worker pool.
    - --project=gsm-project-382212 : This specifies the project ID where you want to create the pool.
    - --location=us-central1 : This specifies the region where you want to create the pool.
    - --worker-pool-id=my-first-privatepool : This specifies the ID for your private pool.
    - --file=workerpool.json : This specifies the path to your configuration file.
    
    3. Verify the pool creation:
    
    After running the command, you can verify that the pool has been created by
    running the following command:
    
    gcloud builds worker-pools list
    
    Additional notes:
    
    - You can customize the configuration file to meet your specific needs. For
    example, you can change the machine type, disk size, or network settings.
    - You can also create private worker pools using the Cloud Build API or th
     Cloud Console.
    
    I hope this helps! Let me know if you have any other questions.
    
  4. 위 응답을 보면 PRIVATEPOOL_CONFIG_FILE 변수를 대체할 구성 파일을 전달해야 하는 것으로 보이므로, Gemini에 구성 파일 만들기에 관한 지원을 요청합니다. 다음 프롬프트를 입력합니다.

    Can you show me an example of a Cloud Build private pool config file?
    

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

    Sure. Here is an example of a Cloud Build private pool config file:
    
    privatePoolV1Config:
       networkConfig:
         egressOption: NO_PUBLIC_EGRESS<br>
         peeredNetwork: 'projects/my-project/global/networks/my-network'
         peeredNetworkIpRange: '10.1.2.0/24'
       workerConfig:
         diskSizeGb: '100'
         machineType: 'e2-standard-4'
    
    This config file creates a private pool with the following
    properties:
    
    • The pool is not connected to the public internet.
    • The pool is connected to the `my-network` VPC network.
    • The pool's workers have a `100GB` boot disk and a
      `e2-standard-4` machine type.
    
    For more information, see the Cloud Build documentation.
    
  5. 빌드 작업자가 공개 인터넷에 액세스할 수 없는 자체 구성 파일을 작성하기 시작합니다. Google Cloud 콘솔로 이동하여 Cloud Shell 편집기를 실행합니다.

  6. Cloud Shell에서 다음 명령어를 실행하여 egressOptionNO_PUBLIC_EGRESS로 설정합니다.

    cat << EOF >> cloudbuild-privatepool-config.yaml
    
    privatePoolV1Config:
      networkConfig:
        egressOption: NO_PUBLIC_EGRESS
    
    EOF
    
  7. 구성 파일에서 사용할 수 있는 나머지 옵션에 대해 확신할 수 없으므로 Gemini에 프롬프트를 입력하여 지원을 받습니다.

    Is there a default value for any of these options?
    

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

    Yes, there are default values for some of the options in the private
    pool config file. For example, the default value for egressOption is
    ALLOW_PUBLIC_EGRESS, which means that the private pool will have
    access to the public internet. The default value for diskSizeGb is
    100, and the default value for machineType is e2-medium.
    
    For a full list of the default values, see the Cloud Build documentation.
    
  8. 구성 파일에 이미 설정된 기본값 중 일부를 Gemini가 제공하는 것을 확인하고, 문서를 읽은 후 구성 파일을 있는 그대로 사용해도 좋다고 판단합니다. Cloud Shell에서 새로 만든 구성 파일에 앞서 Gemini가 제공한 gcloud 명령어를 전달합니다.

    gcloud builds worker-pools create max-pool-test \
        --config-from-file cloudbuild-privatepool-config.yaml \
        --region us-central1
    
  9. 작업자가 생성되면 컨테이너는 pip와 같은 공개 패키지 관리자에 액세스할 수 없습니다. 비공개 패키지 호스팅에 대해 잘 이해하고 있는지 확인하려고 합니다. 다음 프롬프트를 입력합니다.

    If I create a private pool with NO_PUBLIC_EGRESS enabled, can I use
    Artifact Registry to host my packages privately and access them from
    a private pool?
    

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

    Yes, you can use Artifact Registry to host your packages privately
    and access them from a private pool. To do this, you will need to
    create a private pool with NO_PUBLIC_EGRESS enabled and then
    configure your Artifact Registry repository to use the private pool.
    For more information, see the Cloud Build documentation.
    
  10. Artifact Registry 저장소를 만들기로 결정합니다. Gemini 창에 다음 프롬프트를 입력합니다.

    How can I use gcloud to create a private Docker repository for
    container images in Artifact Registry?
    

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

    To create a private Docker repository for container images in
    Artifact Registry, you can use the following command:
    
    gcloud artifacts repositories create REPOSITORY_NAME \\\
        --repository-format=docker \\\
        --location=LOCATION \\\
        --description="DESCRIPTION" \\\
        --kms-key=KMS_KEY
    
    Where:
    
    • REPOSITORY_NAME is the name of your repository.
    • LOCATION is the location of your repository.
    • DESCRIPTION is a description of your repository.
    • KMS_KEY is the name of your Cloud Key Management Service key that
      you want to use to encrypt your repository data.
    
    For more information, see the gcloud artifacts repositories create
    documentation.
    

  11. KMS_KEY 변수를 보고 아직 Cloud KMS 키를 만들지 않았음을 깨닫게 됩니다. 다음 프롬프트를 입력합니다.

    Do I need a KMS_KEY?
    

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

    No, you don't need a KMS_KEY to create a private Docker repository
    for container images in Artifact Registry. However, if you want to
    encrypt your container images, you can use a Cloud Key Management Service key. For more
    information, see the Artifact Registry CMEK documentation.
    
  12. 질문에 대한 답변을 토대로 Cloud Shell에서 Gemini가 제공한 gcloud 명령어를 실행합니다.

    gcloud artifacts repositories create max-docker-repo-test \
        --repository-format=docker \
        --location=us-central1 \
        --description="test container repository"
    

Gemini의 지원으로 아티팩트 빌드 및 호스팅을 위한 비공개 작업자 집합과 비공개 저장소가 성공적으로 생성되었습니다.

삭제

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

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

    리소스 관리로 이동

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

다음 단계