Implementa una aplicación de Kubernetes con conectores de Workflows
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Crea un clúster de GKE con el conector de la API de Kubernetes Engine y crea una implementación y un servicio de Kubernetes con el conector de la API de Kubernetes.
Muestra de código
Salvo que se indique lo contrario, el contenido de esta página está sujeto a la licencia Atribución 4.0 de Creative Commons, y los ejemplos de código están sujetos a la licencia Apache 2.0. Para obtener más información, consulta las políticas del sitio de Google Developers. Java es una marca registrada de Oracle o sus afiliados.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","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)."]]