Déployer une application Kubernetes à l'aide de connecteurs Workflows
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Créez un cluster GKE à l'aide du connecteur API Kubernetes Engine, puis créez un déploiement et un service Kubernetes à l'aide du connecteur Kubernetes API.
Exemple de code
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","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)."]]