Lesson 47 of 60 · Go
Deploying Go Services to Docker & Kubernetes
Duration: 25 minutes
Dockerfile (multi‑stage)
This lesson explains the main concept clearly with beginner-friendly examples and background so you can learn why the code works.
# Build stage
FROM golang:1.22-alpine AS builder
WORKDIR /src
COPY . .
RUN CGO_ENABLED=0 go build -o /app ./cmd/app
# Runtime stage
FROM alpine:latest
RUN addgroup -S app && adduser -S -G app app
USER app
COPY --from=builder /app /app
ENTRYPOINT ["/app"]
Kubernetes Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: go-app
spec:
replicas: 3
selector:
matchLabels:
app: go-app
template:
metadata:
labels:
app: go-app
spec:
containers:
- name: go-app
image: ghcr.io/yourname/go-app:latest
ports:
- containerPort: 8080
Create a Service (NodePort or LoadBalancer) to expose the app.