- Building Google Cloud Platform Solutions
- Ted Hunter Steven Porter Legorie Rajan PS
- 347字
- 2025-04-04 14:47:42
Deploying workloads to GKE
The whole point of all the setup and configuration is to finally get to the point where you can deploy workloads to your GKE container clusters. Deploying workloads to GKE has gotten much easier over its lifetime; you can now even deploy simple workloads directly from images in Container Registry using the GCP Cloud Console. The three GKE deployment options are:
- kubectl run using command line parameters
- kubectl apply using YAML deployment file
- Kubernetes Engine Workloads dashboard
As noted earlier in this chapter, scripted deployments are much preferred when repeatability and testability are concerns. The console should only really be used when deploying trial or test workloads in an R&D type environment. The pinnacle of scripted deployments is when you get to parameterized YAML that is driven by an orchestration engine, for example Terraform, allowing you to test and deploy all of your workloads via a tried and true pipeline.
Here is an example of a basic deployment YAML file:
---
apiVersion: "extensions/v1beta1"
kind: "Deployment"
metadata:
name: "nginx-1"
namespace: "default"
labels:
app: "nginx-1"
spec:
replicas: 3
selector:
matchLabels:
app: "nginx-1"
template:
metadata:
labels:
app: "nginx-1"
spec:
containers:
- name: "nginx"
image: "nginx:latest"
---
apiVersion: "autoscaling/v1"
kind: "HorizontalPodAutoscaler"
metadata:
name: "nginx-1-hpa"
namespace: "default"
labels:
app: "nginx-1"
spec:
scaleTargetRef:
kind: "Deployment"
name: "nginx-1"
apiVersion: "apps/v1beta1"
minReplicas: 1
maxReplicas: 5
targetCPUUtilizationPercentage: 80
Using YAML for deployment definitions gives you a number of advantages, including:
- Convenience: You'll no longer have to add all of your parameters to the command line
- Maintenance: YAML files can be added to source control, so you can track changes
- Flexibility: You'll be able to create much more complex structures using YAML than you can on the command line
Regardless of how workloads are deployed to GKE, the workload dashboard can be utilized to monitor the details and events associated with the workload:

The GKE Workload dashboard also provides some other really helpful functionality, such as the ability to generate the YAML deployment file for a workload, and shortcuts for several kubectl CLI commands that can be executed without ever leaving the console using Cloud Shell.