Gemini for Google Cloud アシスタンスを使用して GKE クラスタを作成および変更する

このチュートリアルでは、Google Cloud の AI を活用したコラボレーターである Gemini for Google Cloud を使用して、Autopilot で Google Kubernetes Engine(GKE)クラスタを作成、テスト、変更する方法について説明します。Gemini を使用して、シンプルなアプリをクラスタにデプロイし、アプリの日々のメンテナンスの時間枠を作成する方法について説明します。このチュートリアルは、あらゆる経験レベルのネットワーク エンジニアを対象としています。

目標

  • Gemini にコンテキスト ベースの質問をすることで、GKE にアプリをデプロイするために使用できるさまざまな Google サービスを探索します。
  • Gemini に、GKE クラスタに基本アプリをデプロイするために使用できるコマンドを提供するよう指示します。
  • Gemini を使用して、シェルコマンドを説明し、生成することで、GKE クラスタの作成、探索、変更を行います。

使用する Google Cloud プロダクト

このチュートリアルでは、課金対象である次の Google Cloud プロダクトを使用します。料金計算ツールを使うと、予想使用量に基づいて費用の見積もりを作成できます。

  • GKE。GKE は、コンテナ化されたアプリケーションを大規模にデプロイして管理できるマネージド Kubernetes サービスです。料金について詳しくは、GKE の料金をご覧ください。

  • 選択できます Gemini は、Google Cloud の常時接続のコラボレーターで、デベロッパーやデータ サイエンティストなどの幅広いユーザーに、生成 AI を活用したアシスタンスを提供します。統合されたアシスタンスのエクスペリエンスを提供するために、Gemini は多くの Google Cloud プロダクトに組み込まれています。

始める前に

  1. GKE API を有効にします。
  2. Gemini が Google Cloud ユーザー アカウントとプロジェクト用に設定されていることを確認します。

Google Cloud の Kubernetes を探索する

次の例では、あなたは、ウェブ アプリケーションを開発するチームのインフラストラクチャ設定を担当するインフラストラクチャ管理者であるとします。組織全体はコンテナと Kubernetes を使用して標準化されているため、チームは Google Cloud で Kubernetes を使用してウェブ アプリケーションを実行する方法を理解したいと考えています。チームはまた、インフラストラクチャの管理オーバーヘッドをできる限り少なくしたいと思っています。

Google Cloud コンソールで、Gemini とチャットしてヘルプを受けることができます。[Gemini] ペインを使用してプロンプトを入力します。プロンプトは、必要なヘルプを説明する質問やステートメントです。Gemini によってレスポンスが返されます。Gemini がプロンプトやそのレスポンスをデータとして使用してモデルをトレーニングすることはありせん。詳細については、Gemini for Google Cloud がデータを使用する方法をご覧ください。

良い回答を生成するプロンプトの作成方法については、Gemini により適したプロンプトを作成するをご覧ください。

Google Cloud で Kubernetes を実行する方法を決定するのを Gemini に支援するよう指示するには、次の手順に沿って操作します。

  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] ペインで delete アイコンをクリックしてから、[チャットをリセット] をクリックして、チャットの履歴をリセットします。

Autopilot モードの GKE クラスタを作成する

あなたは、Autopilot モードの GKE を使用した Kubernetes の実行に精通していないとします。開発者向けのクラスタをプロビジョニングする前に、あなたはまず、Autopilot モードで GKE をテストすることにしました。このセクションでは、Autopilot モードの GKE クラスタでテスト ウェブアプリを作成して実行する際に、Gemini によるサポートを指示します。

  1. [Gemini] ペインに、次のプロンプトを入力してから、[送信] をクリックします。

    How do I create a GKE Autopilot cluster?
    

    Gemini は、Google Cloud コンソールと Google Cloud CLI を使用してクラスタを作成する手順を返します。

  2. CLUSTER_NAMEREGIONPROJECT_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 が会話履歴から Deployment 名 hello-server を pull できていることがわかります。

  3. 次に、ウェブサーバーが稼働中で、リクエストを適切に処理しているかどうかを確認します。デプロイされたアプリケーションを表示するには、作成した Kubernetes Service から外部 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. In the Google Cloud console, go to the Manage resources page.

    Go to Manage resources

  2. In the project list, select the project that you want to delete, and then click Delete.
  3. In the dialog, type the project ID, and then click Shut down to delete the project.

次のステップ