On this page
Short answer
A Go service in production on Kubernetes needs six things checked before it takes real traffic: a supported Go release, a CPU count that follows the container limit, a memory limit set below the container's, explicit HTTP timeouts, a profiling endpoint, and a shutdown that finishes in-flight requests. Go 1.25 and later handle the CPU count for you, as long as you have not overridden it.
A Go service in production on Kubernetes needs six things checked before it takes real traffic: a supported Go release, a CPU count that follows the container limit, a memory limit set below the container's, explicit HTTP timeouts, a profiling endpoint, and a shutdown that finishes in-flight requests. Go 1.25 and later handle the CPU count for you, as long as you have not overridden it.
If a service is already throttled or being killed, our Golang consulting work starts at the same list.
Which Go version should I run in production?
Each Go major release is supported until two newer major releases exist. Go 1.27.0 was released on 19 August 2026, per the Go release page, so Go 1.27 and Go 1.26 receive fixes, and Go 1.25 no longer does. The supported line moves every February and August, so check the release page each time and pin the toolchain in go.mod and your CI image. go version -m ./binary prints the Go version a deployed binary was built with, which is the quickest way to audit a fleet.
Does Go respect the Kubernetes CPU limit?
Since Go 1.25, yes on Linux. The runtime reads the cgroup CPU bandwidth limit and sets GOMAXPROCS to that limit if it is lower than the number of logical CPUs, and it updates the value if the limit changes. Kubernetes CPU requests are ignored, only limits count. Both behaviours switch off if GOMAXPROCS is set by environment variable or by a call to runtime.GOMAXPROCS, or with the GODEBUG settings containermaxprocs=0 and updatemaxprocs=0.
Before Go 1.25 the default was the host CPU count, so a pod limited to 2 CPUs on a 64-core node ran 64 threads against a 2-CPU quota. Kubernetes enforces a CPU limit by throttling, which shows up as latency spikes at the 99th percentile rather than errors. Look for a hand-set GOMAXPROCS or an old automaxprocs import carried over from that period, and remove it unless you have a reason. Our use case on Go CPU throttling and memory limits covers diagnosis in more depth.
How do I set GOMEMLIMIT in a container?
GOMEMLIMIT (or debug.SetMemoryLimit) is a soft limit on the total memory the Go runtime uses. The Go GC guide recommends leaving 5-10% of headroom below the container limit for memory the runtime does not track, such as cgo allocations. Kubernetes kills a container that passes its memory limit, but only when the kernel detects memory pressure, so an overshoot is not always an instant kill.
| Container memory limit | Suggested GOMEMLIMIT |
Why |
|---|---|---|
| 512 MiB | 460MiB | About 10% headroom |
| 1 GiB | 920MiB | About 10% headroom |
| 4 GiB | 3700MiB | Same ratio, more room for cgo or large stacks |
Do not combine GOGC=off with a memory limit when the process shares memory with others. Near the limit the collector can run almost constantly and starve the program (the guide calls this thrashing), so alert on GC CPU and heap growth, not only on restarts.
Which HTTP server settings are mandatory?
The zero value of http.Server has no timeouts: a zero or negative ReadTimeout or WriteTimeout means none, and IdleTimeout falls back to ReadTimeout. Set at least these:
ReadHeaderTimeout, so a slow client cannot hold a connection open while sending headers.IdleTimeout, so unused keep-alive connections are closed.- A
contextdeadline on every outbound call and database query. A handler with no deadline can wait forever on a dependency.
Choose WriteTimeout carefully if you stream large responses, because it covers the whole response write.
How do I shut down a Go service gracefully on Kubernetes?
Kubernetes sends SIGTERM to the main process, waits for the grace period (30 seconds by default, terminationGracePeriodSeconds), then sends SIGKILL. In Go, catch the signal, stop accepting work and let Server.Shutdown drain. Shutdown closes listeners, closes idle connections, then waits indefinitely for active ones, so give it a context with a timeout shorter than the grace period.
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
go func() {
if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Fatal(err)
}
}()
<-ctx.Done()
shutCtx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
_ = srv.Shutdown(shutCtx)
ListenAndServe returns http.ErrServerClosed as soon as Shutdown is called, so the program must wait for Shutdown to return, not exit when main falls out of the goroutine. Fail the readiness probe first (or when the signal arrives) so the Service stops sending new requests while connections drain.
How should I build the Go binary for a container?
go build produces a single Go binary, and the go tool enables cgo when a C compiler is available. Set the environment variable CGO_ENABLED=0 to disable cgo when you do not need it, which keeps the binary independent of C libraries and makes a small container image practical. Build with -trimpath to strip file system paths from the executable. The linker flags -ldflags="-s -w" omit the symbol table and DWARF debug information and shrink the file, but they also remove data profilers and debuggers use, so keep an unstripped build from the same commit. Pass GOMAXPROCS, GOMEMLIMIT and GODEBUG as environment variables in the pod spec, not baked into the image, so each environment can change them.
How do I profile a Go service in production?
Import net/http/pprof for its side effect and it registers handlers under /debug/pprof/ on the default mux. Do not expose that mux to the internet. Serve it on a separate port bound to localhost or a cluster-internal address, and reach it with kubectl port-forward. As of Go 1.22 the paths accept only GET.
Take a 30-second CPU profile and a heap profile during the problem, not afterwards:
go tool pprof http://localhost:6060/debug/pprof/profile?seconds=30go tool pprof http://localhost:6060/debug/pprof/heapcurl http://localhost:6060/debug/pprof/goroutine?debug=2for goroutine stacks, which shows a leak as thousands of identical stacks.
For incidents you cannot reproduce, Go 1.25 added the runtime/trace.FlightRecorder API. It records an execution trace into an in-memory ring buffer and writes out the last few seconds only when your code calls WriteTo, which is far smaller than a continuous trace.
What should I put on the pre-production checklist?
- Go version supported, toolchain pinned, binary built with
-trimpathand an unstripped copy kept. GOMAXPROCSnot hand-set, or set deliberately.GOMEMLIMITabout 90-95% of the container memory limit.ReadHeaderTimeout,IdleTimeoutand context deadlines in place.- SIGTERM handled,
Shutdowntimeout under the grace period. - pprof on a private port, a throttling metric and a memory metric on a dashboard.
Sources
Frequently Asked Questions
Does Go set GOMAXPROCS from the Kubernetes CPU limit?
From Go 1.25 on Linux, yes. It uses the cgroup CPU limit and ignores CPU requests, and it updates if the limit changes. Setting `GOMAXPROCS` by hand turns this off.
What should GOMEMLIMIT be in a container?
Below the container memory limit, with 5-10% headroom for memory the Go runtime does not track. It is a soft limit, so it does not replace sizing the container for your real peak.
Which Go versions are supported in 2026?
Per the Go release page, Go 1.27 and Go 1.26 as of 19 November 2026. Go supports each major release until two newer ones exist, so the set changes at each February and August release.
Talk to an engineer
Need a hand with Go?
Senior engineers who run it in production. Get a quote or a free consultation, no sales pitch.

