|
| 1 | + .. Licensed to the Apache Software Foundation (ASF) under one |
| 2 | + or more contributor license agreements. See the NOTICE file |
| 3 | + distributed with this work for additional information |
| 4 | + regarding copyright ownership. The ASF licenses this file |
| 5 | + to you under the Apache License, Version 2.0 (the |
| 6 | + "License"); you may not use this file except in compliance |
| 7 | + with the License. You may obtain a copy of the License at |
| 8 | +
|
| 9 | + .. http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +
|
| 11 | + .. Unless required by applicable law or agreed to in writing, |
| 12 | + software distributed under the License is distributed on an |
| 13 | + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | + KIND, either express or implied. See the License for the |
| 15 | + specific language governing permissions and limitations |
| 16 | + under the License. |
| 17 | +
|
| 18 | +
|
| 19 | +
|
| 20 | +Google Kubernetes Engine Operators |
| 21 | +================================== |
| 22 | + |
| 23 | +`Google Kubernetes Engine (GKE) <https://cloud.google.com/kubernetes-engine/>`__ provides a managed environment for |
| 24 | +deploying, managing, and scaling your containerized applications using Google infrastructure. The GKE environment |
| 25 | +consists of multiple machines (specifically, Compute Engine instances) grouped together to form a cluster. |
| 26 | + |
| 27 | +.. contents:: |
| 28 | + :depth: 1 |
| 29 | + :local: |
| 30 | + |
| 31 | +Prerequisite Tasks |
| 32 | +^^^^^^^^^^^^^^^^^^ |
| 33 | + |
| 34 | +.. include:: _partials/prerequisite_tasks.rst |
| 35 | + |
| 36 | +Manage GKE cluster |
| 37 | +^^^^^^^^^^^^^^^^^^ |
| 38 | + |
| 39 | +A cluster is the foundation of GKE - all workloads run on on top of the cluster. It is made up on a cluster master |
| 40 | +and worker nodes. The lifecycle of the master is managed by GKE when creating or deleting a cluster. |
| 41 | +The worker nodes are represented as Compute Engine VM instances that GKE creates on your behalf when creating a cluster. |
| 42 | + |
| 43 | +.. _howto/operator:GKECreateClusterOperator: |
| 44 | + |
| 45 | +Create GKE cluster |
| 46 | +"""""""""""""""""" |
| 47 | + |
| 48 | +Here is an example of a cluster definition: |
| 49 | + |
| 50 | +.. exampleinclude:: ../../../../airflow/providers/google/cloud/example_dags/example_kubernetes_engine.py |
| 51 | + :language: python |
| 52 | + :start-after: [START howto_operator_gcp_gke_create_cluster_definition] |
| 53 | + :end-before: [END howto_operator_gcp_gke_create_cluster_definition] |
| 54 | + |
| 55 | +A dict object like this, or a |
| 56 | +:class:`~google.cloud.container_v1.types.Cluster` |
| 57 | +definition, is required when creating a cluster with |
| 58 | +:class:`~airflow.providers.google.cloud.operators.kubernetes_engine.GKECreateClusterOperator`. |
| 59 | + |
| 60 | +.. exampleinclude:: ../../../../airflow/providers/google/cloud/example_dags/example_kubernetes_engine.py |
| 61 | + :language: python |
| 62 | + :dedent: 4 |
| 63 | + :start-after: [START howto_operator_gke_create_cluster] |
| 64 | + :end-before: [END howto_operator_gke_create_cluster] |
| 65 | + |
| 66 | +.. _howto/operator:GKEDeleteClusterOperator: |
| 67 | + |
| 68 | +Delete GKE cluster |
| 69 | +"""""""""""""""""" |
| 70 | + |
| 71 | +To delete a cluster, use |
| 72 | +:class:`~airflow.providers.google.cloud.operators.kubernetes_engine.GKEDeleteClusterOperator`. |
| 73 | +This would also delete all the nodes allocated to the cluster. |
| 74 | + |
| 75 | +.. exampleinclude:: ../../../../airflow/providers/google/cloud/example_dags/example_kubernetes_engine.py |
| 76 | + :language: python |
| 77 | + :dedent: 4 |
| 78 | + :start-after: [START howto_operator_gke_delete_cluster] |
| 79 | + :end-before: [END howto_operator_gke_delete_cluster] |
| 80 | + |
| 81 | +Manage workloads on a GKE cluster |
| 82 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 83 | + |
| 84 | +GKE works with containerized applications, such as those created on Docker, and deploys them to run on the cluster. |
| 85 | +These are called workloads, and when deployed on the cluster they leverage the CPU and memory resources of the cluster |
| 86 | +to run effectively. |
| 87 | + |
| 88 | +.. _howto/operator:GKEStartPodOperator: |
| 89 | + |
| 90 | +Run a Pod on a GKE cluster |
| 91 | +"""""""""""""""""""""""""" |
| 92 | + |
| 93 | +There are two operators available in order to run a pod on a GKE cluster: |
| 94 | + |
| 95 | +* :class:`~airflow.providers.cncf.kubernetes.operators.kubernetes_pod.KubernetesPodOperator` |
| 96 | +* :class:`~airflow.providers.google.cloud.operators.kubernetes_engine.GKEStartPodOperator` |
| 97 | + |
| 98 | +``GKEStartPodOperator`` extends ``KubernetesPodOperator`` to provide authorization using Google Cloud credentials. |
| 99 | +There is no need to manage the ``kube_config`` file, as it will be generated automatically. |
| 100 | +All Kubernetes parameters (except ``config_file``) are also valid for the ``GKEStartPodOperator``. |
| 101 | +For more information on ``KubernetesPodOperator``, please look at: :ref:`howto/operator:KubernetesPodOperator` guide. |
| 102 | + |
| 103 | +We can enable the usage of :ref:`XCom <concepts:xcom>` on the operator. This works by launching a sidecar container |
| 104 | +with the pod specified. The sidecar is automatically mounted when the XCom usage is specified and it's mount point |
| 105 | +is the path ``/airflow/xcom``. To provide values to the XCom, ensure your Pod writes it into a file called |
| 106 | +``return.json`` in the sidecar. The contents of this can then be used downstream in your DAG. |
| 107 | +Here is an example of it being used: |
| 108 | + |
| 109 | +.. exampleinclude:: ../../../../airflow/providers/google/cloud/example_dags/example_kubernetes_engine.py |
| 110 | + :language: python |
| 111 | + :dedent: 4 |
| 112 | + :start-after: [START howto_operator_gke_start_pod_xcom] |
| 113 | + :end-before: [END howto_operator_gke_start_pod_xcom] |
| 114 | + |
| 115 | +And then use it in other operators: |
| 116 | + |
| 117 | +.. exampleinclude:: ../../../../airflow/providers/google/cloud/example_dags/example_kubernetes_engine.py |
| 118 | + :language: python |
| 119 | + :dedent: 4 |
| 120 | + :start-after: [START howto_operator_gke_xcom_result] |
| 121 | + :end-before: [END howto_operator_gke_xcom_result] |
| 122 | + |
| 123 | +Reference |
| 124 | +^^^^^^^^^ |
| 125 | + |
| 126 | +For further information, look at: |
| 127 | + |
| 128 | +* `GKE API Documentation <https://cloud.google.com/kubernetes-engine/docs/reference/rest>`__ |
| 129 | +* `Product Documentation <https://cloud.google.com/kubernetes-engine/docs/>`__ |
| 130 | +* `Kubernetes Documentation <https://kubernetes.io/docs/home/>`__ |
0 commit comments