GCP allows you to choose an app environment that matches the needs of your app. More control over the infrastructure usually implies greater operational burden.
If your needs change, it isn’t a problem. As long as you use Google Client Libraries in your app to work with GCP services, you can usually move to another execution environment.
type | execution environment |
---|---|
Fully Managed | Cloud Dataflow |
Cloud Functions | |
Cloud Run | |
App Engine flexible env | |
GKE | |
Highly Customizable | Compute Engine |
Summary
GCP provides a range of options to run your app code.
Cloud Dataflow and Cloud Run are fully managed.
App Engine, GKE and Compute Engine offer steadily increasing abilities to customize your execution environment.
Fully managed compute environments require minimal setup and operations. On the other hand hihgly customizable environments require greater operational and management efforts to keep the application running optimally.
Cloud Dataflow
Create serverless, elastic data pipelines with Cloud Dataflow
Cloud Dataflow is a serverless execution engine for executing parallel data processing pipelines that are developed using Apache Beams SDK. It supports fast simplified pipeline development.
It integrates with GCP services for streaming events ingestion using Cloud Pub/Sub and data warehouse using BigQuery. It also integrates with ML.
A pipeline comprises your entire data processing tasks including reading input data, transforming the data and writing output data. Cloud data flow uses other managed services such as Compute Engine, Stackdriver Logging, Cloud Storage, BigQuery, Cloud Pub/Sub and Cloud Firestore to execute your pipelines.
Cloud Dataflow does a fantastic job of removing operational overhead.
Use Cloud Dataflow for high-volume data processing
With systems such as Spark or Hadoop, users spend a significant amount of time tuning their jobs. They have to stimate the number of workers to use for their job or cluster. A single config might not even be sufficient because resource needs can dynamically change over the lifetime of the job.
With Cloud Dataflow you don’t need to specify work accounts, it auto scales. It adds workers when CPU utilization and backlog increase and removes them when these metics decrease. Dynamic workload re-balancing reduces overall completion time and reduces costs by keeping all workers busy. It provides better predictability of overall job completion time.
Cloud Dataflow is ideal for streaming and batch data pipelines.
Cloud Functions
With them you can develop an application that’s event-driven, serverless and highly scalable. Each function is a lightweight microservice that enables you to integrate application components and data sources.
They’re ideal for microservices that require a small piece of code to quickly process data related to an event.
Develop event-driven, serverless, highly scalable microservices with Cloud Function
An application that allows users to upload images that contain text to a bucket.
-
The OCR Cloud Function is triggered when a new image is uploaded to the images bucket. This function uses Cloud Vision API to extract text from images and then cues up the next in Cloud Pub/Sub for translation.
-
The translator Cloud Function is triggered and invokes the Cloud Translation API to translate the text. It cues up the text in the file writer Cloud Pub/Sub.
-
The file writer Cloud Function writes the translated text for each image as separate files in Cloud Storage.
These services scale automatically, depending on the volume of incoming data and required compute resources.
Focus on Code. Node.js and Google Cloud Client libraries
When using the Node.js runtime, your function source code must be exported in a node.js module. You don’t need to upload zip files with package dependencies. You can specify any dependencies for your node.js Cloud Function in a package.json file. The Cloud Functions service automatically installs all dependencies before running your code.
You can use Google Cloud Client libraries to programmatically interact with other GCP services.
Use Cloud Functions to enable event-driven processing or to develop lightweight microservices
Cloud Functions can be used in a variety of use cases that require event-driven processing or lightweight microservices. You can use Cloud Functions for lightweight extract transform load or ETL operations.
You can also use them to process data or messages that are published to a Cloud Pub/Sub topic. They can also serve as webhooks.
App Engine Flexible Environment
App Engine FE enables you to quickly deploy your app without manual infrastructure set up. It automatically applies critical backward compatible updates and security updates. Using it, you can deploy with zero downtime.
You can use it to get started with a microservice architecture for your app.
Deploy scalable web and mobile backends in any language with App Engine FE
App Engine flexible environment is an excellent option for deploying web applications, backend for mobile apps, HTTP APIs and internal business applications.
It provides default settings for infrastructure components. You can customize settings such as network, subnetwork, potr forwarding and instance tags. SSH access to VM instances in the flexible environment is disabled by default. You can enable route access to the underlying VM instances.
App Engine FE runs a Docker image for your app. If needed, you can generate the Docker Image of the app and run it in other container-based environments such as GKE. You can use Google Client Libraries to programmatically interact with other GCP services.
Go from code to production with a single command
After you develop your app you can deploy your test, staging or prod environment with a single command.
When you do it, it automatically uploads your source code to Cloud Storage, builds a Docker image for your app with the runtime environment and pushes the image to container registry. You don’t need to set up any Docker scripts for apps that use one of App Engines native runtime environments.
Behind the scenes, App Engine sets up a load balancer and runs your app in three zones to ensure that your app is always up and running. App Engine launches and auto scales Compute Engine instances to run your app and ensure that your app can scale up or down depending on traffic volume. It also sets up other services that are crucial for app monitoring and management such as monitoring, logging, error reporting, health checks and SSL.
Deploy safely with zero downtime
App Engine flexible environment enables you to perform Canary testing. You can verify a production release before serving any external traffic. You can perform A/B testing of your app and deploy updates by easily splitting traffic between the current and the newer version. After you verify that the newer versions works you can migrate all traffic to the newer version without any downtime.
Use App Engine FE for higly scalable web-focused apps
You can use App Engine for HTTP or HTTPS request responses and applications that deploy public endpoints. You can also implemented CI/CD pipelines that use Jenkins or Spinnaker to deploy apps.
Consider other compute environments
- You should consider other environments such as GKE or Compute Engine if your app needs to support other network protocols besides HTTP and HTTPS.
- You can’t write data to persistent disks with App Engine. Only to in-memory files.
- It’s not ideal for apps with Spiky or very low traffic. At least 2 instances are running at all times to serve traffic.
App Engine Standard Environment is an option for apps with spiky or very low traffic
Apps that run on Standard Environment must use App Engine Standard APIs. This APIs are only supported in the Standard Environment, so if you’ve built an app using this APIs you cannot run it on another platform such as GKE, Cloud Functions or Compute Engine.
GKE (Google Kubernetes Engine)
Kubernetes is an open-source platform for deploying, scaling and operating containers
Kubernetes provides you with a framework to run distributed, containerized systems, resiliently and at scale. It takes care of many operational tasks such as scaling app components, providing stable network obstructions, orchestrating failovers, rolling out deployments and management of secrets and configurations.
A Kubernetes cluster contains master and non-master nodes. The nodes in a cluster are the machines such as VMs, physicals servers etc that run your apps. The master controls each node.
A pod is a group of containers that share networking and storage resources on the node. A pod represents one or more related containers on your cluster.
The kubernetes control pane consist of the services running on the master and the kubelet processes running on the non-master nodes.
GKE is a managed service for Kubernetes
GKE helps you deploy, manage and scale Kubernetes environments for your containerized apps on GCP.
It makes easy to bring your Kubernetes workloads into the Cloud.
GKE has many features
GKE is fully managed, which means you don’t have to provision the unedrlying resources. It uses a container optimized OS to run your workloads, these OS are maintained by Google and are optimized to scale quickly with a minimal resource footprint.
When you use GKE, you start by directing the system to instantiate a cluster for you. GKE has an auto-upgrade feature to ensure your clusters are always automatically upgraded with the latest stable version of Kubernetes.
The VM that hosts your containers in GKE cluster are called nodes.
If you enable GKE’s auto-repair feature, the service will repair unhealthy nodes for you, it will make periodic health-checks on each node of the cluster. If a node is determined to be unhealthy and requires a repair, GKE will drain the node. This means to cause its workloads to exit gracefully and recreate the node.
Just as Kubernetes supports scaling workloads, GKE supports scaling the cluster itself. GKE seamlessly integrates with Cloud Build and Container Registry. This allows you to automate deployment using private container images that you have securely stored in Container Registry. GKE also integrates with Cloud Identity and Access Management, which allows you to control access through the use of accounts and role permissions.
GKE integrates with Stackdriver Monitoring to help you understand your app performance. GKE is integrated with virtual private Cloud and makes use of GCP’s networking features. The GCP console provides insights into GKE clusters and their resources and allows you to view, inspect and delete resources in the clusters.
Use GKE for complex, portable applications
GKE supports any app runtime that you can package as a Docker Image. You can run apps that have been built by using the Cloud Client Libraries. GKE is ideally suited for containerized apps including third-party containerized software.
You can run your container image on Kubernetes in a hybrid Cloud or multi-cloud environment. This is specially helpful when you have some parts of your app running on-premises and other parts in the Cloud.
You can use GKE to run containerized apps that use network protocols other than HTTP and HTTPS, that deploy private endpoints or that are based on a microservice architecture.
GKE simplifies infrastructure service provisioning for your apps
GKE simplifies many of the operational tasks associated with the provisioning and managing the infrastructure required for complex apps that you would have to manage separately in a Kubernetes environment that you built yourself. With GKE, GCP persistent disks are automatically provisioned by default when you create Kubernetes persistent volumes to provide storage for stateful apps. GKE also automatically provisions GCP network load balancers when you deploy Kubernetes network load balancer services and GCP HTTP and HTTPS load balancers when you configure Kubernetes ingress resources. This eliminates the need to configure and manage these resources manually.
GKE has native support for Stackdriver, providing seamless integration with its tools for app and service monitoring and troubleshooting.
Use GKE for greater control over how GCP resources are deployed for your applications
GKE makes it easy to deploy and scale clusters. You can describe the compute, memory, network and storage resources that you want to make available across all the containers required by your apps and GKE will provision and manage the underlying GCP resources automatically.
You can either deploy fixed size clusters, or you can configure your clusters to automatically scale adding or removing compute instances in response to the resources required by the containers running inside the cluster.
Deploy apps using standard Kubernetes tools
Inside your GKE clusters, you deploy and manage your containerized apps in exactly the same way you would with any other Kubernetes environment. Most operational tasks are carried out using the kubectl command in conjunction with YAML manifest files that are used to define the desired state for the resources that you need to deploy for your app. These resources include the containerized app itself, but can also include other resources such as network configs, load balancing services and security polices. While you can deploy ad hoc resources directly using kubectl command, the recommended best practice is to define configs using YAML manifest files. These files define the properties of the containers that are used for the components in your apps and network services, security polices and other Kubernetes objects that are used to deliver resilient, scalable, containerized apps.
Apps can be deployed as deployments, where Kubernetes will ensure that a specified number of replicas for a pod or set of pods is running at all times. The deployment shown here is for stateless components. There are a range of other resource types that you can define using YAML manifests that you can deploy and manage with the kubectl command.
Use GKE as a part of your CI/CD pipeline
As a part of a CI/CD pipeline, you can generate a new Docker image for each code commit and automatically deploy the image to development, test and production environments.
Cloud Build, Container Registry and GKE can be used to create a strong CI/CD system. GKE requires that your app be packaged and deployed as a container image.
Cloud Run
Cloud Run lets you focus on development
Clud Run is a managed compute platform that enables you to run stateless containers that are invokable via web requests or Cloud Pub/Sub events. Cloud Run is serverless. It abstracts away all infrastructure management so you can focus on developing apps.
It’s built on Knative and gives you the choice of running your containers either fully managed with Cloud Run or in your own GKE cluster with Cloud Run on GKE.
If your app is not stateless or must respond to requests or events delivered using protocols other than HTTP or HTTPS, then Cloud Run will not be suitable.
If you need access to VPC resources or need to deploy your containers to custom machine types, consider Cloud Run on GKE.
Cloud Run doesn’t restrict the way you code
Many serverless platforms add constraints around support for languages and libraries or even restrict the way you code. Cloud Run enables you to write code your way by allowing you to easily deploy any stateless containers that listen for requests or events delivered by HTTP. Containers offer flexibility and portability of workloads.
With Cloud Run you can build your apps in any language by using whatever frameworks and tools you wish.
Cloud Run allows you to focus on writing code
It enables you to run request or event-driven stateless workloads without having to worry about servers. It abstracts away all infrastructure management, such as provisioning, configuring and managing servers so you can focus on writing code. It automatically scales up and down from zero almost instantaneously depending on traffic. So you never have to worry about scale configuration.
With Cloud Run you can choose to deploy your stateless container with a consistent developer experience to a fully managed environment or to your own GKE cluster. This common experience is enabled by Knative an open API and runtime environment built on Kubernetes that gives you freedom to move your workloads across different environments and platforms.
Deploy automatically scaled containerized applications with a single command
Once you have deployed your app, Cloud Run horizontally scales your container image automatically in order to handle a received requests, then scales down when demand decreases. You only have to pay for the CPU memory and networking consumed during request handling.
Compute Engine
Run your app on high-performance, scalable VMs with Compute Engine
Compute Engine gives you the greatest amount of control over your infrastructure compared to the other execution environments. It supports predefined machine types. You can also create custom machine types to create VMs with the optimal amount of CPU and memory for your workloads. Compute Engine supports persistent disks and SSDs. You can also launch preemtible VMs for large compute and batch jobs. You can run your choice of OS. You can also use a shared image from the GCP community or bring your own OS.
Use Compute Engine for full control of infrastructure
Use CE for full control of your infrastructure. CE enables you to create highly customized VMs for specialized apps that have unique compute or OS requirements. You can install and patch software running on the VMs. You can create managed instance groups based on an instance template. You can configure global load balancing and auto scaling of the managed instance groups. You can configure global load balancing and auto scaling of the managed instance groups.
CE can perform health checks and replace unhealthy instances in an instance group. It auto scales based on the traffic volume in specific regions.
Use Compute Engine for maximum flexibility
CE offers you the most flexibility to configure your resources for the specific type of app that you need to run. You can run any third-party license software on CE. You can attach GPUs to CE using VMs to speed up ML and data processing workloads. You can use CE for apps that require network protocols other than HTTP or HTTPS.
Use Compute Engine for lift-and-shift migration
CE is ideal for lift and shift. You can move VMs from your on-premises data center or another cloud provider to GCP without changing your app
Consider startup time
Consider startup time when you use CE instances. A VM can take up to 60 seconds to spin up and become available. You can however launch hundreds of VMs within a few minutes. To ensure that VM instances launch quickly, profile your startup scripts to identify and correct steps that take a longer time to complete.
If you’re downloading and installing a lot of software, consider creating a custom image with all the software pre-installed. Plan ahead for burst of traffic by setting appropiate target usage levels in your auto scaling policy.