Skip to main content

On This Page

Deploy a Container to GKE Using deployment.yaml and kubectl

2 min read
Share

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-gateway service.
  • “ConfigMaps over hardcoded env vars”: Demonstrated by GATEWAY_HTTP_ADDR and JAEGER_ENDPOINT values sourced from app-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.requests can lead to pod eviction during cluster resource contention.

References:


Continue reading

Next article

Avoid These 5 Terraform Mistakes That Break DevOps Workflows

Related Content