Skaffold Dev CLI

Skaffold cheatsheet — continuous dev for Kubernetes. skaffold dev for hot-reload, skaffold build, skaffold run, skaffold deploy. Automate build-push-deploy on every code change.

8 min read

What it is

Skaffold is a command-line tool that facilitates continuous development for Kubernetes applications. It automates the build, push, and deploy workflow, allowing you to iterate rapidly on your code and see changes reflected in your cluster almost instantly.

Installation

Linux

curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64 \
  && chmod +x skaffold \
  && sudo mv skaffold /usr/local/bin/

macOS

curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/latest/skaffold-darwin-amd64 \
  && chmod +x skaffold \
  && sudo mv skaffold /usr/local/bin/

Windows (PowerShell)

Invoke-WebRequest -OutFile skaffold.exe https://storage.googleapis.com/skaffold/releases/latest/skaffold-windows-amd64.exe
# Move skaffold.exe to your PATH, e.g., C:\Program Files\skaffold

Core Concepts

  • Skaffold Configuration (skaffold.yaml): This is the central configuration file where you define your application’s build, test, and deploy steps, as well as Skaffold’s behavior.
  • Build: Skaffold can build container images using various tools like Docker, Jib, Bazel, or buildpacks.
  • Test: You can define tests that run after your application is built and deployed.
  • Deploy: Skaffold deploys your application to Kubernetes using tools like kubectl, Helm, or Kustomize.
  • Development Loop: Skaffold watches your source files for changes. Upon detecting a change, it rebuilds your image, redeploys your application, and can even forward ports for live debugging.

Commands / Usage

Starting the Development Loop

  • skaffold dev: Starts the Skaffold development loop. This command builds, deploys, and then continuously watches for changes.

    skaffold dev
    

    Explanation: This is the primary command for live development. Skaffold will build your application, deploy it to Kubernetes, and then monitor your source files for changes, automatically rebuilding and redeploying upon detection.

  • skaffold dev --port-forward: Starts the development loop and forwards specified ports from your deployed application to your local machine.

    skaffold dev --port-forward
    

    Explanation: Useful for accessing services running inside your Kubernetes cluster locally, like a web server or database.

  • skaffold dev --watch-poll: Starts the development loop using polling instead of filesystem events for detecting changes.

    skaffold dev --watch-poll
    

    Explanation: Fallback mechanism if filesystem watching is unreliable in your environment.

  • skaffold dev --build-concurrency 4: Sets the number of parallel build jobs.

    skaffold dev --build-concurrency 4
    

    Explanation: Speeds up builds by running multiple build operations simultaneously if your skaffold.yaml defines multiple deployable artifacts.

  • skaffold dev --build-artifact <artifact-name>: Only build and deploy the specified artifact.

    skaffold dev --build-artifact my-api
    

    Explanation: Allows you to focus on a specific part of your application during development.

  • skaffold dev --sync: Enables file sync for faster updates without rebuilding the entire image.

    skaffold dev --sync
    

    Explanation: For languages that support it (e.g., Go, Python), Skaffold can copy changed files directly into the running container, significantly speeding up hot-reloading.

Building and Deploying

  • skaffold build: Builds your application’s container images without deploying them.

    skaffold build
    

    Explanation: Useful for CI/CD pipelines to just build images and push them to a registry.

  • skaffold build -t my-app:latest: Builds your application and tags the resulting image as my-app:latest.

    skaffold build -t my-app:v1.0
    

    Explanation: Allows explicit image tagging.

  • skaffold build --file-path ./Dockerfile: Specifies a custom Dockerfile path for building.

    skaffold build --file-path ./backend/Dockerfile
    

    Explanation: When you have multiple Dockerfiles or non-standard naming.

  • skaffold deploy: Deploys your application to Kubernetes using the configured deployer.

    skaffold deploy
    

    Explanation: Deploys the application based on the skaffold.yaml configuration.

  • skaffold run: Builds and deploys your application. This is a one-time operation, not a continuous loop.

    skaffold run
    

    Explanation: Equivalent to running skaffold build followed by skaffold deploy. Good for initial deployments or in CI/CD.

Debugging and Port Forwarding

  • skaffold debug: Starts the development loop, builds, deploys, and attaches a debugger to your application.

    skaffold debug
    

    Explanation: Sets up the necessary port forwarding and debugger configurations for live debugging.

  • skaffold debug --debugger-port 5005: Attaches the debugger to a specific port.

    skaffold debug --debugger-port 5005
    

    Explanation: Useful when your application’s debugger listens on a non-default port.

  • skaffold port-forward: Starts port forwarding for a running application without initiating a full development loop.

    skaffold port-forward
    

    Explanation: Manually forwards ports defined in your skaffold.yaml or specified via flags.

Application Management

  • skaffold delete: Deletes the deployed resources from your Kubernetes cluster.

    skaffold delete
    

    Explanation: Cleans up the Kubernetes resources managed by Skaffold.

  • skaffold apply: Builds and deploys your application, similar to skaffold run, but also handles updates and deletions.

    skaffold apply
    

    Explanation: A more idempotent command that ensures the cluster state matches the Skaffold configuration.

  • skaffold render: Renders the deploy manifests (e.g., kubectl manifests, Helm charts) without deploying them.

    skaffold render
    

    Explanation: Useful for inspecting the generated Kubernetes manifests before they are applied.

Configuration and Status

  • skaffold config list: Displays the current Skaffold configuration.

    skaffold config list
    

    Explanation: Shows global configuration settings like default Kubernetes context or registry.

  • skaffold config set <key> <value>: Sets a Skaffold configuration value.

    skaffold config set default-repo my-docker-registry.com/my-project
    

    Explanation: Configures Skaffold’s global behavior.

  • skaffold status: Reports the current status of your Skaffold deployment.

    skaffold status
    

    Explanation: Checks if Skaffold is running, what’s deployed, and if any errors occurred.

Workspace Management

  • skaffold init: Initializes a skaffold.yaml file for your project.

    skaffold init
    

    Explanation: Scans your project for common patterns (e.g., Dockerfiles, Helm charts) and generates a basic skaffold.yaml.

  • skaffold init --enable-build --enable-deploy: Initializes Skaffold with specific features enabled.

    skaffold init --enable-build=docker --enable-deploy=kubectl
    

    Explanation: Guides you through creating a skaffold.yaml by asking questions about your project setup.

  • skaffold fix: Attempts to automatically fix common issues in your skaffold.yaml.

    skaffold fix
    

    Explanation: Helps resolve syntax errors or misconfigurations in your Skaffold configuration file.

Common Patterns

  • Hot Reloading Python/Node.js Apps with File Sync:

    skaffold dev --sync
    

    Explanation: Skaffold will copy changed files directly into the running container, enabling very fast iteration for interpreted languages.

  • Building and Pushing Images for CI:

    skaffold build --push
    

    Explanation: Builds all images defined in skaffold.yaml and pushes them to the configured registry. The --push flag is often implicit when running skaffold build in a CI environment configured with a default registry.

  • Deploying a Helm Chart: Ensure your skaffold.yaml is configured for Helm:

    deploy:
      helm:
        releases:
          - name: my-app
            chartPath: ./charts/my-app
    

    Then run:

    skaffold dev
    

    Explanation: Skaffold will build your image, tag it, update the Helm chart with the new image tag, and then deploy the chart.

  • Deploying with kubectl and Overlays: Ensure your skaffold.yaml is configured for kubectl with Kustomize:

    deploy:
      kubectl:
        manifests:
          - k8s/deployment.yaml
          - k8s/service.yaml
        kustomize:
          paths:
            - kustomize/overlays/dev
    

    Then run:

    skaffold dev
    

    Explanation: Skaffold builds your image, tags it, patches the Kubernetes manifests with the new image tag (or uses Kustomize overlays), and applies them.

  • Debugging a Java Application: Configure your skaffold.yaml for debugging:

    deploy:
      kubectl:
        manifests:
          - k8s/deployment.yaml
    profiles:
      - name: debug
        activation:
          - kubeContext: docker-desktop # or your context
        build:
          artifacts:
            - image: my-java-app
              docker:
                dockerfile: Dockerfile.debug
        deploy:
          kubectl:
            # Add debug args to your deployment manifest or use a separate debug manifest
            # Example: Add JVM debug args to deployment spec
    

    Then run:

    skaffold dev -p debug
    

    Explanation: Skaffold will build using Dockerfile.debug, deploy, and ensure the necessary debugging ports are forwarded and accessible for your IDE.

  • Forwarding Multiple Ports:

    skaffold dev --port-forward=8080:80,5432:5432
    

    Explanation: Manually specifies which local ports should be forwarded to which container ports.

Gotchas

  • Image Tagging: By default, Skaffold tags images with a unique digest. If you need predictable tags (e.g., latest or a specific version) for your deploy step, you must configure this in skaffold.yaml under the build.artifacts.image or build.tagPolicy.
  • skaffold dev vs skaffold run: dev is for continuous development with automatic rebuilding/redeploying. run is a one-time build and deploy.
  • Default Repository: If you don’t specify a default repository in skaffold.yaml or via skaffold config set default-repo, Skaffold might try to push to Docker Hub using your username, or fail if no default is set and no registry is specified in the image name.
  • File Sync Limitations: File sync only works for certain languages and requires specific configurations. It doesn’t rebuild the image, only copies files into the running container.
  • Kubernetes Context: Skaffold uses your current kubectl context by default. Ensure you are targeting the correct cluster. You can override this with the --kube-context flag or by configuring it in skaffold.yaml.
  • skaffold init Defaults: The skaffold init command makes assumptions. Always review and adjust the generated skaffold.yaml to fit your project’s specific needs.
  • Build Artifacts: If you have multiple artifacts defined in skaffold.yaml, skaffold dev will build and deploy all of them by default. Use --build-artifact or --deploy-artifact to target specific ones.
  • Remote Build Issues: When building remotely (e.g., Kaniko, Jib), ensure the necessary permissions and configurations are in place for Skaffold to communicate with the builder and the registry.