Deploy a Container to GKE Using deployment.yaml and kubectl
These articles are AI-generated summaries. Please check the original sources for full details.
DevPill #3: How to deploy a container to your Kubernetes cluster (GKE)
Deploying a container to Google Kubernetes Engine (GKE) requires a deployment.yaml file and kubectl commands. One example specifies memory and CPU limits for the api-gateway container.
Why This Matters
Kubernetes abstracts infrastructure complexity but demands precise configuration. Misconfigured resource limits or missing ConfigMaps can cause deployment failures or runtime errors, leading to increased debugging time and potential service outages.
Key Insights
- “8081 port mapping in deployment.yaml, 2025”: Ensures correct traffic routing for the
api-gatewayservice. - “ConfigMaps over hardcoded env vars”: Demonstrated by
GATEWAY_HTTP_ADDRandJAEGER_ENDPOINTvalues sourced fromapp-config. - “gcloud CLI used by DevOps teams”: For cluster authentication with
gcloud container clusters get-credentials.
Working Example
apiVersion: apps/v1
kind: Deployment
metadata:
name: api-gateway
spec:
replicas: 1
selector:
matchLabels:
app: api-gateway
template:
metadata:
labels:
app: api-gateway
spec:
containers:
- name: api-gateway
image: us-central1-docker.pkg.dev/<project-id>/<repository-name>/api-gateway
ports:
- containerPort: 8081
resources:
requests:
memory: "128Mi"
cpu: "125m"
limits:
memory: "128Mi"
cpu: "125m"
env:
- name: GATEWAY_HTTP_ADDR
valueFrom:
configMapKeyRef:
key: GATEWAY_HTTP_ADDR
name: app-config
- name: JAEGER_ENDPOINT
valueFrom:
configMapKeyRef:
key: JAEGER_ENDPOINT
name: app-config
apiVersion: v1
kind: Service
metadata:
name: api-gateway
spec:
type: LoadBalancer
ports:
- port: 8081
targetPort: 8081
selector:
app: api-gateway
Practical Applications
- Use Case: Deploying a microservice API gateway on GKE with external monitoring via Jaeger.
- Pitfall: Omitting
resources.requestscan lead to pod eviction during cluster resource contention.
References:
Continue reading
Next article
Avoid These 5 Terraform Mistakes That Break DevOps Workflows
Related Content
Init container cascade when every kubectl patch reverts in 10 seconds
Kubernetes recovery of a fanout service where manual patches reverted every 10 seconds due to a hidden node-side admission script.
Optimizing Mac Kubernetes Labs: Migrating from Multipass to OrbStack
Learn how OrbStack reduces Kubernetes VM boot times from 60 seconds to under 3 seconds while optimizing resource allocation on Apple Silicon.
Building a Secured AI-Driven SRE Platform for Kubernetes Observability
Engineer George Ezejiofor implements a secure AI-driven observability stack for AKS that reduces incident investigation time to under two minutes using reasoning layers.