Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. Go Programming Bootcamp

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.

Info

Set GOMAXPROCS to the number of CPU cores inside the container for optimal concurrency.

Previous: Building a HTTP/2 Server with TLSNext: Versioning & Release Management (Semantic Import Versioning)