Konektor untuk Kubernetes Engine

Konektor Workflows yang menentukan fungsi bawaan yang digunakan untuk mengakses aplikasi berbasis container Kubernetes Engine dalam alur kerja.

Jelajahi lebih lanjut

Untuk dokumentasi mendetail yang menyertakan contoh kode ini, lihat artikel berikut:

Contoh kode

YAML

# This workflow demonstrates how to use the Cloud Kubernetes Engine connector.
# The workflow creates a GKE cluster and then deletes it.
# Each of these steps waits until the long-running operation of creating or deleting the GKE
# cluster is completed.
# Expected successful output: "SUCCESS"

main:
  params: []
  steps:
    - init:
        assign:
          - project_id: ${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}
          - cluster_zone: "us-central1-a"
          - cluster_id: "[fill in a cluster ID]"
          - cluster_full_name: ${"projects/" + project_id + "/locations/" + cluster_zone + "/clusters/" + cluster_id}
    - create_k8s_cluster:
        call: googleapis.container.v1.projects.zones.clusters.create
        args:
          projectId: ${project_id}
          zone: ${cluster_zone}
          body:
            cluster:
              name: ${cluster_id}
              initial_node_count: 1
            parent: ${"projects/" + project_id + "/locations/" + cluster_zone}
    - assert_running:
        call: assert_cluster_status
        args:
          expected_status: "RUNNING"
          project_id: ${project_id}
          cluster_zone: ${cluster_zone}
          cluster_id: ${cluster_id}
          cluster_full_name: ${cluster_full_name}

    - delete_k8s_cluster:
        call: googleapis.container.v1.projects.zones.clusters.delete
        args:
          projectId: ${project_id}
          zone: ${cluster_zone}
          clusterId: ${cluster_id}
          name: ${cluster_full_name}
    - the_end:
        return: "SUCCESS"

assert_cluster_status:
  params:
    [expected_status, project_id, cluster_zone, cluster_id, cluster_full_name]
  steps:
    - get_cluster:
        call: googleapis.container.v1.projects.zones.clusters.get
        args:
          projectId: ${project_id}
          zone: ${cluster_zone}
          clusterId: ${cluster_id}
          name: ${cluster_full_name}
        result: cluster
    - compare:
        switch:
          - condition: ${cluster.status == expected_status}
            next: end
    - fail:
        raise: ${"Expected VM status is " + expected_status + ". Got " + cluster.status + " instead."}

Langkah selanjutnya

Untuk menelusuri dan memfilter contoh kode untuk produk Google Cloud lainnya, lihat browser contoh Google Cloud.