Kubernetes Deploy Basics for Go

Updated

September 8, 2026

Kubernetes Deploy Basics for Go

Overview

A minimal production shape: container image, Deployment, Service, probes, resources. Go’s single binary fits multi-stage images well (chapter 70).

Deployment sketch

apiVersion: apps/v1
kind: Deployment
metadata:
  name: bookstore
spec:
  replicas: 2
  selector:
    matchLabels: { app: bookstore }
  template:
    metadata:
      labels: { app: bookstore }
    spec:
      securityContext:
        runAsNonRoot: true
        runAsUser: 65532
      containers:
        - name: app
          image: ghcr.io/org/bookstore:1.2.3
          ports: [{ containerPort: 8080 }]
          env:
            - name: ADDR
              value: ":8080"
          readinessProbe:
            httpGet: { path: /readyz, port: 8080 }
            periodSeconds: 5
          livenessProbe:
            httpGet: { path: /livez, port: 8080 }
            periodSeconds: 10
          resources:
            requests: { cpu: "100m", memory: "128Mi" }
            limits: { memory: "256Mi" }
          securityContext:
            allowPrivilegeEscalation: false
            readOnlyRootFilesystem: true

Service

apiVersion: v1
kind: Service
metadata:
  name: bookstore
spec:
  selector: { app: bookstore }
  ports: [{ port: 80, targetPort: 8080 }]

Graceful stop

  • terminationGracePeriodSeconds ≥ app shutdown timeout
  • Fail readiness on SIGTERM first

Config & secrets

envFrom:
  - secretRef: { name: bookstore-secrets }

Mount secrets as files when possible (TOKEN_FILE pattern).

Rules of thumb

Do Don’t
Probes + resources Unlimited memory “to fix OOM” forever
Immutable tags (:1.2.3) :latest in prod
Non-root Root containers by habit

Try next

  1. Deploy locally with kind/minikube.
  2. Break readiness; observe Service endpoints.
  3. Rollout image; confirm zero-downtime with probes.