A Fast Local Kubernetes Dev Loop with Skaffold

Testing a service inside Kubernetes during development normally means a chain of manual steps for every change: build an image, tag it, push or load it into the cluster, update the manifest, apply it, and wait for the rollout. Skaffold automates that loop. skaffold dev watches your source files and rebuilds and redeploys on every save, streams the pod logs to your terminal, and cleans up when you stop it.
This guide sets up Skaffold for a small Go service on a local cluster (Docker Desktop, kind or minikube), shows how to reach the service with automatic port forwarding, and explains when file sync can skip the rebuild entirely, and when it can't.
What Skaffold Replaces
Kubernetes runs images, not source code, so every code change has to become a new image before the cluster can run it. By hand, that's:
- Code Change: Edit a file.
- Image Build:
docker build -t my-app . - Image Push:
docker push my-registry/my-app:latest - Manifest Update: Edit
k8s-deployment.yamlto point to the new image tag. - Deployment:
kubectl apply -f k8s-deployment.yaml - Verification: Wait for the pod to restart and test.
Skaffold does all of it on save, and tags each image uniquely, so Kubernetes always rolls out the new build. Re-applying a manifest that still says :latest often changes nothing at all, because the pod spec is unchanged. It detects common local clusters (Docker Desktop, kind, minikube) and makes new images available to them without pushing to a registry.
Prerequisites
Before we dive in, ensure you have the following installed and configured:
- Docker Desktop: With Kubernetes enabled, or a local Kubernetes cluster (Minikube/Kind).
kubectl: Configured to interact with your local cluster.skaffoldCLI: Install Skaffold.- A text editor and a command-line terminal.
Step-by-Step: Accelerating Development with Skaffold
Let's walk through setting up a simple Go microservice and integrating Skaffold for rapid local development.
Step 1: Prepare a Sample Microservice
Create a project directory and initialize a Go module, which creates the go.mod file the Dockerfile copies:
mkdir skaffold-go-app && cd skaffold-go-app
go mod init example.com/skaffold-go-appCreate main.go:
package main
import (
"fmt"
"log"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello from Skaffold-powered Microservice V1!")
}
func main() {
http.HandleFunc("/", handler)
log.Println("Server starting on port 8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}Next, define a Dockerfile to containerize our Go application:
# Build stage
FROM golang:1.23-alpine AS builder
WORKDIR /app
# Copy module files first so dependency downloads are cached between builds
COPY go.mod ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -o /go-app
# Final stage: just the binary
FROM gcr.io/distroless/static-debian12
COPY --from=builder /go-app /go-app
EXPOSE 8080
ENTRYPOINT ["/go-app"]Comments in a Dockerfile must be on their own line. A line like COPY go.mod ./ # comment treats # and every word after it as extra source paths, and the build fails. Copying go.mod before the source means the go mod download layer is reused whenever only .go files change, which keeps rebuilds fast.
Step 2: Define Kubernetes Deployment
Now, let's create the Kubernetes manifests for our application. This will include a Deployment to run our container and a Service to expose it within the cluster.
Create k8s-deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: skaffold-go-app
spec:
selector:
matchLabels:
app: skaffold-go-app
replicas: 1
template:
metadata:
labels:
app: skaffold-go-app
spec:
containers:
- name: go-app
image: skaffold-go-app # Skaffold replaces this with the tag it just built
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: skaffold-go-app
spec:
selector:
app: skaffold-go-app
ports:
- protocol: TCP
port: 80
targetPort: 8080Step 3: Initialize Skaffold
Navigate to your project root in the terminal and let Skaffold initialize its configuration. Skaffold is smart enough to auto-detect your Dockerfile and Kubernetes manifests.
skaffold initSkaffold detects the Dockerfile and manifest and writes a skaffold.yaml similar to this (the exact apiVersion depends on your Skaffold version):
apiVersion: skaffold/v4beta7
kind: Config
metadata:
name: skaffold-go-app
build:
artifacts:
- image: skaffold-go-app
docker:
dockerfile: Dockerfile
local:
push: false # Important for local clusters like Docker Desktop K8s
manifests:
rawYaml:
- k8s-deployment.yaml
deploy:
kubectl: {}
portForward:
- resourceType: service
resourceName: skaffold-go-app
port: 80
localPort: 8080The portForward section isn't generated by skaffold init, so add it yourself. It forwards localhost:8080 to the Service while skaffold dev runs, which works the same on every local cluster.
push: false keeps images local. On Docker Desktop, the cluster shares Docker's image store, so a local build is immediately available. For kind and minikube, Skaffold loads the image into the cluster for you (kind load or minikube's image store), as long as the current kubectl context points at that cluster.
Step 4: Run with Skaffold Dev Mode for Live Reloading
Start the development loop. Skaffold builds the image, deploys it, and then watches your source files for changes:
skaffold devSkaffold builds the image, deploys it, starts the port forward, and streams the pod's logs into your terminal. Test it:
curl http://localhost:8080
# Expected output: Hello from Skaffold-powered Microservice V1!Now, let's experience live reloading. Open main.go and change the message:
// ...
fmt.Fprintf(w, "Hello from Skaffold-powered Microservice V2 - Live Reloaded!")
// ...Save the file. Skaffold detects the change, rebuilds the image (reusing the cached dependency layer), deploys a pod with the new tag and reconnects the port forward. Hit the endpoint again:
curl http://localhost:8080
# Expected output: Hello from Skaffold-powered Microservice V2 - Live Reloaded!No manual docker build, push, or kubectl apply! This is the power of Skaffold's inner loop.
Step 5: Skip Rebuilds with File Sync (Interpreted Languages)
For a compiled language like Go, every change needs a new binary, so a rebuild is unavoidable. Make it fast with layer caching, or use Skaffold's ko builder, which builds Go images without a Dockerfile.
For interpreted languages, Skaffold can copy changed files straight into the running container instead of rebuilding. For a Node.js service whose dev server already reloads on file changes (node --watch, nodemon):
build:
artifacts:
- image: node-service
docker:
dockerfile: Dockerfile.dev
sync:
manual:
- src: "src/**/*.js"
dest: /app # path inside the containerChanges to files matching src are copied into the container within a second or two, and the dev server inside picks them up. Changes to anything else, such as package.json or the Dockerfile, still trigger a full rebuild. The container image has to include the dev server and run as a user allowed to write to dest.
💡 Tip: Keep production and development Dockerfiles separate if needed (
DockerfileandDockerfile.dev), and use Skaffold profiles to switch between them, so the production image stays minimal while the dev image includes watchers and debug tools.
Step 6: Cleaning Up
Once you're done, simply press Ctrl+C in the terminal running skaffold dev. Skaffold will automatically clean up the deployed Kubernetes resources, leaving your cluster tidy.
Summary
- Let
skaffold devrun the loop: build, unique tagging, deploy, logs and cleanup on every save. - Add a
portForwardsection so the service is reachable onlocalhostregardless of which local cluster you use. - Keep rebuilds fast by ordering Dockerfile steps so dependency layers are cached, and keep comments on their own lines.
- Use file sync only for interpreted languages with a watching dev server. Compiled services need a rebuild.
