Men-deploy aplikasi Kubernetes menggunakan konektor Workflows
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Buat cluster GKE menggunakan konektor Kubernetes Engine API, lalu buat deployment dan layanan Kubernetes menggunakan konektor Kubernetes API.
Contoh kode
Kecuali dinyatakan lain, konten di halaman ini dilisensikan berdasarkan Lisensi Creative Commons Attribution 4.0, sedangkan contoh kode dilisensikan berdasarkan Lisensi Apache 2.0. Untuk mengetahui informasi selengkapnya, lihat Kebijakan Situs Google Developers. Java adalah merek dagang terdaftar dari Oracle dan/atau afiliasinya.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],[],[],[],null,["# Deploy a Kubernetes application using Workflows connectors\n\nCreate a GKE cluster using the Kubernetes Engine API connector, and create a Kubernetes deployment and service using the Kubernetes API connector.\n\nCode sample\n-----------\n\n### YAML\n\n # This workflow demonstrates how to:\n # 1- Use the Kubernetes Engine API connector to create a GKE cluster.\n # 2- Use the Kubernetes API connector to create a Kubernetes deployment and\n # a service.\n\n main:\n steps:\n - init:\n assign:\n - project_id: ${sys.get_env(\"GOOGLE_CLOUD_PROJECT_ID\")}\n - cluster_location: \"us-central1\"\n - cluster_id: \"workflows-cluster\"\n - cluster_full_name: ${\"projects/\" + project_id + \"/locations/\" + cluster_location + \"/clusters/\" + cluster_id}\n - create_k8s_cluster:\n call: googleapis.container.v1.projects.locations.clusters.create\n args:\n body:\n cluster:\n name: ${cluster_id}\n initial_node_count: 1\n autopilot:\n enabled: true\n parent: ${\"projects/\" + project_id + \"/locations/\" + cluster_location}\n - assert_running:\n call: assert_cluster_status\n args:\n expected_status: \"RUNNING\"\n cluster_id: ${cluster_id}\n cluster_full_name: ${cluster_full_name}\n - create_deployment:\n call: gke.request\n args:\n project: ${sys.get_env(\"GOOGLE_CLOUD_PROJECT_ID\")}\n cluster_id: ${cluster_id}\n location: ${cluster_location}\n method: \"POST\"\n path: \"/apis/apps/v1/namespaces/default/deployments\"\n body:\n kind: Deployment\n metadata:\n name: nginx-deployment\n labels:\n app: nginx\n spec:\n replicas: 3\n selector:\n matchLabels:\n app: nginx\n template:\n metadata:\n labels:\n app: nginx\n spec:\n containers:\n - name: nginx\n image: nginx:1.14.2\n ports:\n - containerPort: 80\n result: create_deployment_result\n - create_service:\n call: gke.request\n args:\n project: ${sys.get_env(\"GOOGLE_CLOUD_PROJECT_ID\")}\n cluster_id: ${cluster_id}\n location: ${cluster_location}\n method: \"POST\"\n path: \"/api/v1/namespaces/default/services\"\n body:\n kind: Service\n apiVersion: v1\n metadata:\n name: nginx-service\n spec:\n ports:\n - name: http\n port: 80\n targetPort: 80\n selector:\n app: nginx\n type: LoadBalancer\n result: create_service_result\n - return_multiple_values:\n return:\n create_deployment_result: ${create_deployment_result}\n create_service_result: ${create_service_result}\n\n assert_cluster_status:\n params:\n [expected_status, cluster_id, cluster_full_name]\n steps:\n - get_cluster:\n call: googleapis.container.v1.projects.locations.clusters.get\n args:\n clusterId: ${cluster_id}\n name: ${cluster_full_name}\n result: cluster\n - compare:\n switch:\n - condition: ${cluster.status == expected_status}\n next: end\n - fail:\n raise: ${\"Expected VM status is \" + expected_status + \". Got \" + cluster.status + \" instead.\"}\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=workflows)."]]