Skaffold Cheat Sheet
Overview
Skaffold is a command-line tool by Google that facilitates continuous development for Kubernetes-native applications. It automates the workflow of building container images, pushing them to registries, and deploying to Kubernetes clusters. Skaffold watches source files and automatically rebuilds and redeploys when changes are detected.
Skaffold supports multiple build tools (Docker, Jib, Buildpacks, ko, Bazel), deploy tools (kubectl, Helm, kustomize, kpt), and tag policies. It is designed for both local development with hot-reload and CI/CD pipelines, with a pluggable architecture that adapts to existing workflows.
Installation
# macOS
brew install skaffold
# Linux
curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64
chmod +x skaffold
sudo mv skaffold /usr/local/bin/
# Windows
choco install skaffold
# Verify
skaffold version
Core Commands
| Command | Description |
|---|---|
skaffold init | Generate skaffold.yaml for a project |
skaffold dev | Continuous build and deploy (watch mode) |
skaffold run | One-time build and deploy |
skaffold build | Build images only |
skaffold deploy | Deploy pre-built images |
skaffold render | Render Kubernetes manifests |
skaffold delete | Delete deployed resources |
skaffold debug | Dev mode with debugger support |
skaffold diagnose | Diagnose configuration issues |
skaffold fix | Fix outdated skaffold.yaml schema |
Configuration
Basic skaffold.yaml
apiVersion: skaffold/v4beta11
kind: Config
metadata:
name: my-app
build:
artifacts:
- image: my-app
docker:
dockerfile: Dockerfile
sync:
manual:
- src: 'src/**/*.js'
dest: /app/src
deploy:
kubectl:
manifests:
- k8s/*.yaml
portForward:
- resourceType: service
resourceName: my-app
port: 8080
localPort: 8080
Multi-Service Project
apiVersion: skaffold/v4beta11
kind: Config
metadata:
name: fullstack-app
build:
artifacts:
- image: frontend
context: frontend
docker:
dockerfile: Dockerfile
- image: backend
context: backend
docker:
dockerfile: Dockerfile
- image: worker
context: worker
deploy:
helm:
releases:
- name: my-app
chartPath: helm/my-app
setValueTemplates:
frontend.image: "{{.IMAGE_FULLY_QUALIFIED_frontend}}"
backend.image: "{{.IMAGE_FULLY_QUALIFIED_backend}}"
worker.image: "{{.IMAGE_FULLY_QUALIFIED_worker}}"
Build Configuration
Docker Build
build:
artifacts:
- image: my-app
docker:
dockerfile: Dockerfile
buildArgs:
NODE_ENV: production
target: runtime
cacheFrom:
- my-app:latest
Buildpacks
build:
artifacts:
- image: my-app
buildpacks:
builder: gcr.io/buildpacks/builder:v1
env:
- GOOGLE_RUNTIME_VERSION=20
File Sync (Hot Reload)
build:
artifacts:
- image: my-app
sync:
manual:
- src: 'src/**/*.py'
dest: /app
infer:
- '**/*.css'
- '**/*.html'
Deploy Configuration
kubectl
deploy:
kubectl:
manifests:
- k8s/deployment.yaml
- k8s/service.yaml
flags:
global:
- --namespace=dev
Helm
deploy:
helm:
releases:
- name: my-release
chartPath: charts/my-app
valuesFiles:
- values.yaml
- values-dev.yaml
setValues:
replicaCount: 2
namespace: dev
createNamespace: true
Kustomize
deploy:
kustomize:
paths:
- kustomize/overlays/dev
Advanced Usage
Profiles
profiles:
- name: dev
activation:
- env: ENV=dev
build:
local:
push: false
deploy:
kubectl:
manifests:
- k8s/dev/*.yaml
- name: production
build:
googleCloudBuild:
projectId: my-project
deploy:
kubectl:
manifests:
- k8s/prod/*.yaml
# Use a profile
skaffold dev -p dev
skaffold run -p production
Custom Actions and Hooks
deploy:
kubectl:
hooks:
before:
- host:
command: ["sh", "-c", "echo 'Pre-deploy hook'"]
after:
- container:
podName: my-app-*
command: ["python", "manage.py", "migrate"]
Debug Mode
# Start with remote debugging
skaffold debug
# Automatically configures debug ports:
# Go: Delve on port 56268
# Node.js: --inspect on port 9229
# Python: debugpy on port 5678
# Java: JDWP on port 5005
CI/CD Pipeline Usage
# Build and push images only
skaffold build --file-output=build.json
# Deploy from build artifacts
skaffold deploy -a build.json
# Render manifests for GitOps
skaffold render -a build.json --output=rendered.yaml
# Run tests after deploy
skaffold verify
Troubleshooting
| Issue | Solution |
|---|---|
| Image not updating | Check tag policy; try skaffold dev --force |
| Sync not working | Verify sync paths match container file structure |
| Port forward fails | Check if port is already in use; verify service name |
| Build slow | Enable caching; use sync instead of rebuild |
| Cluster not reachable | Check kubectl config current-context |
| Schema version mismatch | Run skaffold fix to update skaffold.yaml |
# Diagnose issues
skaffold diagnose
# Verbose logging
skaffold dev -v debug
# Clean up deployed resources
skaffold delete
# Check effective configuration
skaffold inspect