So you wrote a Go API (slay ✨), now you wanna put it out there so people can actually use it. Go is kinda OP here ‘cause it compiles into a single binary (aka just one file to move around). That makes deployment stupid simple compared to languages that need a million dependencies.
Table of Contents
- 1. How to Deploy a Go API
- 1.1 🖥️ 1. Bare Metal (OG Style)
- 1.2 🖥️ 2. Virtual Machines (VMs)
- 1.3 📦 3. Containers (Docker & friends)
- 1.4 ☸️ 4. Kubernetes (The Big Boss)
- 1.5 ⚡ 5. FaaS / Serverless (AWS Lambda, etc)
- 1.6 🛠️ Example Bare-Metal Flow (Simple Demo)
- 1.7 🐳 Example Dockerfile (Container Flow)
- 1.8 💡 TL;DR
- 2. Go API
- 2.1 1. Build your app
- 2.2 2. Pick your deployment style
- 2.3 3. Basic Deployment Example (Bare Metal / VM)
- 2.4 4. Containerized Deployment (Docker)
- 2.5 5. Scale & Go Pro
- 2.6 TL;DR 📝
We are going to explore the following in this post:
- What kind of deployment options suit your needs
- How I deploy in a bare-metal or virtual server
- How I deploy using Docker
- How I deploy using Kubernetes
- How I deploy using serverless
How to Deploy a Go API
There’s a bunch of ways you can deploy, and each has its pros/cons. Let’s run through the main ones:
🖥️ 1. Bare Metal (OG Style)
Basically: run your Go binary straight on a physical server.
- ✅ Pros:
- Zero abstraction layers (so better performance).
- Full control over your setup.
- Great if your app is small/simple.
- ❌ Cons:
- Scaling = pain. You literally have to buy/setup more servers.
- Gotta handle everything yourself (logs, backups, monitoring, etc).
- Can’t “downscale” if traffic drops—you already paid for the hardware.
👉 If you’re running a hobby project or a tiny startup with predictable traffic, bare metal might actually slap. Otherwise… mid.
🖥️ 2. Virtual Machines (VMs)
Think of this as “fake computers” running on top of a real server. AWS EC2, Google Compute, etc.
- ✅ Flexible: spin up/down servers whenever.
- ✅ Pay as you go.
- ❌ Slightly slower (extra virtualization layer).
- ❌ Can get $$ if you don’t manage resources well.
👉 Good middle ground if you like control but don’t wanna mess with physical hardware.
📦 3. Containers (Docker & friends)
Instead of pretending you have full hardware, containers just package your app + dependencies into a lil box.
- ✅ “It works on my machine” becomes “it works everywhere.”
- ✅ Easy to ship + run consistently.
- ❌ Need to learn Dockerfiles & image building.
- ❌ If you have tons of containers, it gets messy.
👉 Perfect for small to medium projects where you want reproducible builds & simple deployment.
☸️ 4. Kubernetes (The Big Boss)
This is basically Docker on steroids. Kubernetes orchestrates tons of containers across clusters.
- ✅ Auto-healing, scaling, networking, load balancing… all built in.
- ✅ Industry standard for big apps.
- ❌ Steep learning curve (like, really steep 💀).
- ❌ Overkill if you’re just running 1–2 services.
👉 If you’re building something big or wanna flex devops skills, Kubernetes is the way.
⚡ 5. FaaS / Serverless (AWS Lambda, etc)
Here you don’t even think about servers. You just upload a function, and it runs when triggered.
- ✅ Zero server management.
- ✅ Cheap if your app is event-driven & low-traffic.
- ❌ Limits (runtime, memory, cold starts).
- ❌ Hard to manage state & complex apps.
👉 Great for quick APIs, background tasks, or side projects. Not great for long-running, stateful systems.
🛠️ Example Bare-Metal Flow (Simple Demo)
- Build your Go binary:
go build my-api.go
- Copy it to your server:
scp my-api user@server:/opt/my-api
- Run it:
/opt/my-api
- (Better) Hook it into
systemd
so it auto-restarts if it crashes.
🐳 Example Dockerfile (Container Flow)
FROM ubuntu:latest
WORKDIR /opt
COPY my-api .
RUN chmod +x my-api
EXPOSE 8080
CMD ["./my-api"]
Then:
docker build -t my-api .
docker run -p 8080:8080 my-api
Boom, your Go API is running in Docker.
💡 TL;DR
Bare Metal = raw power, but manual grind.
VMs = flexible, but pricier.
Containers = consistency & portability.
Kubernetes = god mode for scaling, but high effort.
FaaS = no servers to manage, but limited.
Go API
1. Build your app
Go makes this easy, just compile it into one lil binary:
go build -o myapi main.go
Now you’ve got a single file myapi
that runs anywhere (well, anywhere that matches your GOOS + GOARCH).
2. Pick your deployment style
You got options, depending on vibes + scale:
- Bare Metal: throw the binary on a server & run it. Old school, works fine for hobby stuff.
- VMs (AWS EC2, GCP Compute, etc): a bit fancier, you control the OS + resources.
- Docker Containers: wrap your app into a container for consistency, easier shipping.
- Kubernetes: if you need scaling + self-healing, but steep learning curve.
- Serverless (AWS Lambda, etc): good for small functions or bursty workloads.
3. Basic Deployment Example (Bare Metal / VM)
- Upload your binary:
scp myapi user@yourserver:/opt/myapi
- Run it:
/opt/myapi
- (Optional) Set up systemd so it stays alive:
[Unit] Description=My Go API After=network.target [Service] ExecStart=/opt/myapi Restart=always [Install] WantedBy=multi-user.target
Then:sudo systemctl enable myapi sudo systemctl start myapi
4. Containerized Deployment (Docker)
Dockerfile
:
FROM golang:1.22-alpine AS builder
WORKDIR /app
COPY . .
RUN go build -o myapi main.go
FROM alpine:latest
WORKDIR /opt
COPY --from=builder /app/myapi .
EXPOSE 8080
CMD ["./myapi"]
Build & run:
docker build -t myapi .
docker run -p 8080:8080 myapi
5. Scale & Go Pro
- Add Nginx or Caddy in front as reverse proxy (SSL, routing).
- Add monitoring (Prometheus, Grafana, or even just logs).
- Deploy with Kubernetes if you’re planning to go global 🌍.
TL;DR 📝
go build
→ get your binary.- Upload → run it on server (bare metal, VM, or container).
- Optional: wrap in Docker for portability.
- Use systemd or Kubernetes for scaling & reliability.
- How to Remove Microsoft Store Ads Showing Up on Windows
- How to Fix Nvidia Driver Crashes on Windows 11
- What to Do If Your Phone Is Lost or Stolen
- How to Recover Your Google Account If You Forget Your Password
- Google Issues Emergency Security Warning to 2.5 Billion Gmail Users
- Designing Your REST API with Go: A Complete Guide
- How to Build a REST Client in Go (With Real Code Examples)