Esegui il deployment di un'applicazione Kubernetes utilizzando i connettori Workflows
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Crea un cluster GKE utilizzando il connettore dell'API Kubernetes Engine e crea un deployment e un servizio Kubernetes utilizzando il connettore dell'API Kubernetes.
Esempio di codice
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","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)."]]