Membuat build pribadi dengan bantuan Duet AI

Tutorial ini menunjukkan cara menggunakan Duet AI, kolaborator yang didukung AI di Google Cloud, untuk membuka log dan menyiapkan lingkungan build untuk serangkaian microservice di Google Kubernetes Engine.

Tutorial ini ditujukan bagi engineer DevOps dengan tingkat pengalaman apa pun.

Tujuan

  • Minta Duet AI untuk kueri logging agar Anda dapat mengamati log dari Pod.
  • Pahami cara membangun lingkungan build pribadi dengan meminta Duet AI dengan pertanyaan berbasis konteks.
  • Gunakan Duet AI untuk mempelajari cara menyimpan image container secara pribadi dan aman.

Produk Google Cloud yang digunakan

Tutorial ini menggunakan produk Google Cloud yang dapat ditagih berikut. Gunakan kalkulator harga untuk membuat perkiraan biaya berdasarkan proyeksi penggunaan Anda.

  • Google Kubernetes Engine (GKE). GKE adalah layanan Kubernetes terkelola yang memungkinkan Anda men-deploy dan mengelola aplikasi dalam container dalam skala besar. Untuk mengetahui informasi harga, lihat harga GKE.

  • Cloud Logging. Logging adalah sistem pengelolaan log real time dengan dukungan penyimpanan, penelusuran, analisis, dan pemantauan.

  • Cloud Build. Cloud Build adalah layanan yang menjalankan build Anda di infrastruktur Google Cloud. Cloud Build dapat mengimpor kode sumber dari berbagai repositori atau ruang Cloud Storage, menjalankan build sesuai spesifikasi Anda, dan menghasilkan artefak seperti container Docker atau arsip Java.

  • Artifact Registry. Artifact Registry adalah satu tempat bagi Anda untuk mengelola image container dan paket bahasa. Dengan layanan ini, Anda dapat menyimpan artefak secara terpusat dan membangun dependensi sebagai bagian dari pengalaman Google Cloud yang terintegrasi.

  • Duet AI. Duet AI adalah kolaborator yang selalu aktif di Google Cloud dan menawarkan bantuan yang didukung teknologi AI generatif kepada berbagai pengguna, termasuk developer dan ilmuwan data. Untuk memberikan pengalaman bantuan terintegrasi, Duet AI disematkan di banyak produk Google Cloud.

Sebelum memulai

  1. Pastikan Duet AI sudah disiapkan untuk akun pengguna dan project Google Cloud Anda.
  2. Enable the Google Kubernetes Engine API.

    Enable the API

  3. Di konsol Google Cloud, aktifkan Cloud Shell.

    Aktifkan Cloud Shell

    Di bagian bawah Google Cloud Console, Cloud Shell sesi akan terbuka dan menampilkan perintah command line. Cloud Shell adalah lingkungan shell dengan Google Cloud CLI yang sudah terinstal, dan dengan nilai yang sudah ditetapkan untuk project Anda saat ini. Diperlukan waktu beberapa detik untuk melakukan inisialisasi sesi.

  4. Buat cluster GKE menggunakan perintah gcloud container clusters create:

    gcloud container clusters create test --region us-central1
    

    Perintah membutuhkan waktu beberapa menit untuk dijalankan. Outputnya mirip dengan hal berikut ini:

    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. Clone repositori dan gunakan kubectl untuk men-deploy kumpulan microservice yang membentuk aplikasi web e-commerce ke cluster GKE:

    git clone https://github.com/GoogleCloudPlatform/microservices-demo && cd microservices-demo
    
    kubectl apply -f ./release/kubernetes-manifests.yaml
    
  6. Setelah beberapa menit, dapatkan alamat IP eksternal untuk mengakses aplikasi web Anda di browser:

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

Memahami log untuk workload di GKE

Pada contoh berikut, anggaplah Anda sebagai engineer DevOps yang ditugaskan untuk mewarisi set microservice yang ada yang berjalan di cluster GKE. Untuk memahami lingkungannya, Anda memutuskan ingin memeriksa log dari berbagai microservice.

Di konsol Google Cloud, Anda dapat melakukan chat dengan Duet AI untuk mendapatkan bantuan. Di panel Duet AI, Anda dapat memasukkan prompts, yaitu pertanyaan atau pernyataan yang menjelaskan bantuan yang Anda inginkan, dan Duet AI akan menampilkan respons.

Duet AI tidak menggunakan perintah Anda atau responsnya sebagai data untuk melatih modelnya. Untuk mengetahui informasi selengkapnya, lihat Cara Duet AI di Google Cloud menggunakan data Anda.

Anda tahu bahwa microservice telah di-deploy ke namespace default. Untuk meminta Duet AI membantu Anda memeriksa log, ikuti langkah-langkah berikut:

  1. Di toolbar konsol Google Cloud, klik chat_spark Open Duet AI.
  2. Di panel Duet AI, masukkan perintah berikut:

    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"?
    

    Duet AI menampilkan respons yang mirip dengan berikut ini:

    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. Untuk memeriksa log ini, klik setiap log yang ditampilkan dari kueri. Di setiap log, jika Anda mengklik Explain this query, responsnya akan mirip dengan berikut ini:

    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.
    

Membuat lingkungan build pribadi untuk image container

Setelah memiliki pemahaman yang lebih mendalam tentang beban kerja dari mengamati log, Anda memutuskan untuk menyiapkan infrastruktur dan membangun image container masa depan tim Anda pada sekumpulan pekerja pribadi. Di bagian ini, Anda akan meminta Duet AI untuk membantu Anda memahami cara menjalankan lingkungan build sehingga Anda dapat memigrasikan build ke project Google Cloud.

  1. Di toolbar konsol Google Cloud, klik chat_spark Open Duet AI.
  2. Di panel Duet AI, masukkan perintah berikut:

    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.
    

    Duet AI menampilkan respons yang mirip dengan berikut ini:

    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. Kumpulan pribadi Cloud Build sepertinya merupakan jalur yang tepat ke depan, jadi Anda meminta bantuan Duet AI dalam membuat kumpulan pribadi pertama Anda. Masukkan perintah berikut:

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

    Duet AI menampilkan respons yang mirip dengan berikut ini:

    Sure. To create a private pool, you can use the following gcloud
    command:
    
    gcloud builds worker-pools create PRIVATEPOOL_ID --config-from-file
    PRIVATEPOOL_CONFIG_FILE --region REGION
    
    Where:
    
    • PRIVATEPOOL_ID is a unique identifier for your private pool.
    • PRIVATEPOOL_CONFIG_FILE is the name of your private pool
      config file.
    • REGION is the region where you want to create your private
      pool.
    
    For more information, see the Cloud Build documentation.
    
    Source:
    
    https://cloud.google.com/build/docs/private-pools/create-manage-private-pools
    
  4. Dari respons sebelumnya, tampaknya Anda perlu meneruskan file konfigurasi untuk mengganti variabel PRIVATEPOOL_CONFIG_FILE, sehingga Anda meminta Duet AI untuk membantu Anda membuat file konfigurasi. Masukkan perintah berikut:

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

    Duet AI menampilkan respons yang mirip dengan berikut ini:

    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. Anda mulai membuat file konfigurasi sendiri saat pekerja build tidak memiliki akses ke internet publik. Di Cloud Shell, jalankan perintah berikut, dengan menyetel egressOption ke NO_PUBLIC_EGRESS`:

    cat << EOF >> cloudbuild-privatepool-config.yaml
    
    privatePoolV1Config:
      networkConfig:
        egressOption: NO_PUBLIC_EGRESS
    
    EOF
    
  6. Anda tidak yakin dengan opsi lain yang tersedia dalam file konfigurasi, jadi Anda meminta Duet AI untuk mendapatkan bantuan:

    Is there a default value for any of these options?
    

    Duet AI menampilkan respons yang mirip dengan berikut ini:

    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.
    
  7. Anda melihat bahwa Duet AI menyediakan beberapa nilai default yang telah ditetapkan dalam file konfigurasi, dan setelah membaca dokumentasi, Anda memutuskan bahwa file konfigurasi sudah baik. Di Cloud Shell, teruskan perintah gcloud yang disediakan Duet AI untuk Anda sebelumnya di file konfigurasi yang baru Anda buat:

    gcloud builds worker-pools create max-pool-test \
        --config-from-file cloudbuild-privatepool-config.yaml \
        --region us-central1
    
  8. Setelah pekerja dibuat, Anda menyadari bahwa container tidak akan memiliki akses ke pengelola paket publik, seperti pip. Anda ingin mengonfirmasi pemahaman Anda tentang menghosting paket pribadi. Masukkan perintah berikut:

    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?
    

    Duet AI menampilkan respons yang mirip dengan berikut ini:

    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.
    
  9. Anda memutuskan untuk melanjutkan dengan membuat repositori Artifact Registry. Di panel Duet AI, masukkan perintah berikut:

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

    Duet AI menampilkan respons yang mirip dengan berikut ini:

    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.
    

  10. Setelah melihat variabel KMS_KEY, Anda menyadari bahwa Anda belum membuat kunci Cloud KMS. Masukkan perintah berikut:

    Do I need a KMS_KEY?
    

    Duet AI menampilkan respons yang mirip dengan berikut ini:

    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.
    
  11. Setelah pertanyaan Anda terjawab, di Cloud Shell, Anda dapat menjalankan perintah gcloud yang disediakan Duet AI untuk Anda:

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

Dengan bantuan Duet AI, Anda berhasil membuat kumpulan pekerja pribadi dan repositori pribadi untuk membangun dan menghosting artefak Anda.

Pembersihan

Agar tidak menimbulkan biaya pada akun Google Cloud Anda untuk resource yang digunakan dalam tutorial ini, Anda dapat menghapus project Google Cloud yang dibuat untuk tutorial ini. Atau, Anda dapat menghapus resource satu per satu.

  1. Di konsol Google Cloud, buka halaman Manage resource.

    Buka Manage resource

  2. Pada daftar project, pilih project yang ingin Anda hapus, lalu klik Delete.
  3. Pada dialog, ketik project ID, lalu klik Shut down untuk menghapus project.

Langkah selanjutnya