Deployment Basics
Deploying Go services means building static binaries, containerizing, and running on Kubernetes, AWS ECS, Google Cloud Run, or VM systemd services.
Introduction
Deploying Go services means building static binaries, containerizing, and running on Kubernetes, AWS ECS, Google Cloud Run, or VM systemd services. Go's single binary simplifies deployment — copy one file and run.
Kubernetes Deployment + Service + Ingress is the cloud-native standard. Configure liveness/readiness probes, resource limits, horizontal pod autoscaling, and rolling updates. CI/CD pipelines automate test → build → push → deploy.
This lesson covers K8s manifest essentials, GitHub Actions CI, and zero-downtime rolling deployments — the deployment story interviewers expect from Go backend candidates.
The story
A Go payments service deploys to GKE via GitHub Actions: build and test, push a container to Artifact Registry, apply Kubernetes manifests with rolling updates (maxUnavailable: 0), and verify Prometheus alerts stay green. readinessProbe waits for database connectivity; preStop hook sleeps 5 seconds so the load balancer drains connections before the pod terminates.
Blue-green or canary deploys route 5% traffic to a new version first — Go's fast startup makes rolling back a bad deploy a one-command kubectl rollout undo.
Understanding the topic
Key concepts
- Kubernetes Deployment manages pod replicas.
- Service exposes pods internally; Ingress externally.
- Liveness probe restarts unhealthy pods.
- Readiness probe removes pod from load balancer until ready.
- ConfigMap/Secret inject env configuration.
- HPA scales pods on CPU/memory/custom metrics.
Step-by-step explanation
- CI: go test -race → docker build → push to registry.
- CD: kubectl apply or Helm upgrade.
- Rolling update replaces pods incrementally.
- Readiness waits for DB migration and Ping success.
- Ingress routes HTTPS with cert-manager TLS.
- Monitor with Prometheus metrics and alerting.
Practical code example
Kubernetes Deployment manifest and GitHub Actions CI snippet:
# k8s/deployment.yamlapiVersion: apps/v1kind: Deploymentmetadata:name: go-apispec:replicas: 3selector:matchLabels:app: go-apitemplate:metadata:labels:app: go-apispec:containers:- name: apiimage: ghcr.io/techlearningpro/go-api:1.0.0ports:- containerPort: 8080envFrom:- secretRef:name: go-api-secretsresources:requests:memory: "64Mi"cpu: "100m"limits:memory: "256Mi"cpu: "500m"livenessProbe:httpGet:path: /healthport: 8080initialDelaySeconds: 5readinessProbe:httpGet:path: /healthport: 8080initialDelaySeconds: 3# .github/workflows/ci.yaml snippet# - run: go test -race ./...# - run: docker build -t ghcr.io/org/go-api:$GITHUB_SHA .# - run: docker push ghcr.io/org/go-api:$GITHUB_SHA
Line-by-line code explanation
kind: Deploymenttells Kubernetes this file describes a Deployment, an object that keeps a set of identical pods running and replaces them if they fail.replicas: 3asks Kubernetes to keep three copies of the pod running at the same time.matchLabels:tells the Deployment which pods belong to it, here the ones labelled app: go-api. The pod template further down gives its pods that same label.image: ghcr.io/techlearningpro/go-api:1.0.0names the container image to run, pinned to the 1.0.0 tag. The container listens on port 8080, as declared by containerPort below it.- secretRef:loads every key of the Kubernetes Secret named go-api-secrets as an environment variable in the container, so passwords are not written in this file.requests:is the amount of memory (64Mi) and CPU (100m, a tenth of a core) the scheduler reserves for the container. The limits section below it caps it at 256Mi of memory and 500m of CPU.livenessProbe:makes Kubernetes call GET /health on port 8080 to check the container is still alive. It waits 5 seconds before the first check, and repeated failures cause the container to be restarted.readinessProbe:uses the same /health check, starting after 3 seconds, to decide whether the pod is ready for traffic. A pod that is not ready is taken out of the Service's rotation but is not restarted.go test -race ./...comes from the commented CI snippet. It runs all tests in the project with Go's race detector turned on. The next two comment lines build and push a Docker image tagged with the commit hash.
Key takeaway: The readiness and liveness probes both call the /health path on port 8080. The first decides whether a pod receives traffic, and the second decides whether it is restarted. Requests and limits control how much CPU and memory each pod reserves and may use.
Real-world use
Where you'll use this in production
- Production API on AWS EKS or GKE.
- Serverless Go on Cloud Run with auto-scaling.
- Edge deployment of static Go binary on VM systemd.
- Blue-green or canary releases with Argo Rollouts.
Best practices
- Immutable deployments — new image per release, never patch running container.
- Readiness probe on DB connectivity.
- Set resource requests and limits.
- Use semantic versioning tags plus git SHA.
- Automate rollback on failed health checks.
- Separate staging and production clusters/namespaces.
Common mistakes
- No readiness probe — traffic hits starting pods.
- Latest tag in production — unpredictable deploys.
- Missing resource limits — pod OOM or node exhaustion.
- Secrets baked into image instead of K8s Secret.
- No rollback plan when deployment fails.
Advanced interview questions
Interview Prep
Practice concise answers, then expand each card for the explanation.
1BeginnerQuestionLiveness vs readiness?+
Answer
2BeginnerQuestionWhy Go good for containers?+
Answer
3IntermediateQuestionZero-downtime deploy?+
Answer
4IntermediateQuestionCI pipeline for Go service?+
Answer
5AdvancedQuestionDesign deployment for 99.9% availability.+
Answer
Summary
Deploy Go as container on K8s with probes and resource limits. CI runs tests and builds; CD applies manifests or Helm. Readiness gates traffic; liveness restarts failed pods. Secrets via K8s Secret — never in image layers. Next lesson: interview preparation and final project.