Skaffold
repository·main·Indexed 12 days ago
https://github.com/GoogleContainerTools/skaffoldA CLI tool that automates the build, push, and deploy cycle for Kubernetes applications. It provides building blocks for CI/CD pipelines and supports various builders including Cloud Native Buildpacks, Bazel, docker buildx, and custom shell commands. Skaffold also integrates with kpt for configuration validation and can generate Tekton pipelines via the generate-pipeline command.
What's inside Skaffold
- Skaffold is a command line tool designed to facilitate continuous development for Kubernetes applications. It automates the workflow of building, pushing, and deploying applications. It allows developers to iterate on source code locally and deploy to either local or remote Kubernetes clusters. Additionally, Skaffold provides building blocks that can be used to construct CI/CD pipelines.
Supported Skaffold build environments
mainSkaffold allows you to execute builds in different environments depending on your infrastructure and requirements. The supported build environments are:
- Local build: Builds images on your local machine using local tools (e.g., Docker, Buildpacks).
- In cluster build: Executes the build process directly within your Kubernetes cluster.
- Remotely on Google Cloud Build: Offloads the build process to Google Cloud Build for managed, scalable builds.
Supported Skaffold builder types
mainSkaffold supports several different builder types to create container images from your source code. Depending on your language, build tool, or environment, you can choose from the following builders:
- Docker: Uses a Dockerfile to build images.
- Jib: A container image builder for Java applications that does not require a Docker daemon.
- Bazel: Uses the Bazel build system to create container images.
- Custom build script: Allows you to run any arbitrary shell script or command to build your images.
- ko: A tool for building and deploying Go applications to Kubernetes, optimized for Go's build patterns.
Skaffold core features
mainSkaffold is designed for high-velocity development with the following capabilities:
- Optimized Source to Kubernetes: Automatically detects source changes and handles the build/push/test/deploy pipeline.
- Continuous Feedback: Automatically manages deployment logging and resource port-forwarding.
- Portability: Projects are easily shared via
git cloneandskaffold run. Supports profiles, local user config, and environment variables to handle environment differences. - Platform Awareness: Supports cross-platform and multi-platform builds with automatic platform detection.
- Lightweight: Client-side only; no cluster-side components or maintenance required.
Skaffold CLI command overview
mainThe Skaffold CLI is organized into functional groups: end-to-end pipelines, CI/CD building blocks, project initialization, and utility commands.
End-to-end pipelines
Use these for complete workflows from code to running application:
skaffold run: Build and deploy once.skaffold dev: Trigger the watch loop (build and deploy continuously) and clean up resources on exit.skaffold debug: Run a pipeline in debug mode.
Pipeline building blocks for CI/CD
Use these to execute individual stages of a deployment pipeline:
skaffold build: Build and tag images only.skaffold deploy: Deploy specific images.skaffold delete: Clean up deployed artifacts.skaffold render: Build and tag images, then output the templated Kubernetes manifests.skaffold apply: Apply hydrated manifests to a cluster.
Getting started
skaffold init: Bootstrap a newskaffold.yamlconfiguration.skaffold fix: Upgrade an existingskaffold.yamlfrom an older schema version to a newer one.
Utilities
skaffold help: Print help information.skaffold version: Get the current Skaffold version.skaffold completion: Set up shell tab completion.skaffold config: Manage context-specific parameters.skaffold credits: Export third-party notices (defaults to./skaffold-credits).skaffold diagnose: Run diagnostics to check how Skaffold works in your project.skaffold schema: List and print JSON schemas used forskaffold.yamlvalidation.
Supported Build Tools and Execution Contexts
mainSkaffold supports various tools for building container images across three primary execution contexts: Local Build (using your machine's tools), In Cluster Build (building inside your Kubernetes cluster), and Remote on Google Cloud Build (using Google's infrastructure).
Tool Local Build In Cluster Build Remote (GCB) Dockerfile Yes Yes Yes Jib (Maven/Gradle) Yes - Yes Cloud Native Buildpacks Yes - Yes Bazel Yes - - ko Yes - Yes Custom Script Yes Yes - What is Skaffold and how does it work?
mainSkaffold is a command-line tool designed to facilitate continuous development for container-based and Kubernetes applications. It automates the workflow of building, pushing, and deploying applications, allowing developers to focus on code iteration while Skaffold manages the underlying infrastructure updates.
Core Workflow
When running
skaffold dev, the tool executes a pipeline of stages:- Watch: Collects and watches source code for changes.
- Sync: Syncs files directly to pods (if configured as syncable).
- Build: Builds artifacts from the source code.
- Test: Tests built artifacts using
container-structure-testor custom scripts. - Tag: Tags the artifacts using policy-based tagging.
- Push: Pushes artifacts to a registry (or keeps them local).
- Deploy: Deploys the artifacts to a target environment.
- Monitor: Monitors deployed artifacts, including log aggregation and port-forwarding.
- Cleanup: Cleans up deployed artifacts upon exit (e.g., via
Ctrl+C).
Note that any of these stages can be skipped based on your configuration.
What is HCL (HashiCorp Configuration Language)?
mainHCL is a structured configuration language designed to be both human-friendly and machine-friendly, specifically targeted towards DevOps tools and servers.
Key characteristics include:
- JSON Compatibility: HCL is fully JSON compatible. You can use JSON as valid input for any system expecting HCL, which allows machines to generate JSON to interact with HCL-based tools.
- Human-Centric: Unlike JSON, HCL supports comments. Unlike YAML, it aims to provide a clearer structure to avoid common indentation or syntax guessing errors.
- Specialized for DevOps: It provides a middle ground between full programming languages (like Ruby) and pure data languages (like JSON).
What is kpt and how does it help with Kubernetes packaging?
mainkpt is an open-source tool for Kubernetes packaging. It uses a standard format to manage the lifecycle of configuration manifests, specifically allowing you to:
- Bundle and publish configurations
- Customize manifests
- Update configurations
- Apply manifests to clusters
A key advantage of
kptis its ability to prune resources accurately using a three-way merge strategy, which helps maintain the desired state of your cluster more reliably than standard tools.Configure lifecycle hooks in Skaffold
mainSkaffold supports lifecycle hooks that allow you to execute commands at different stages of the development workflow. Based on the design schema, hooks can be categorized into
preandpoststages.There are two primary types of hook executions:
- Host-level commands: Executed on the machine running Skaffold using
command. - Container-level commands: Executed within a specific container in a running pod. For these artifact-scoped hooks (such as those used during
buildorsync), you can optionally specifycontainer-nameandpod-prefixto target specific environments.
Note: The schema uses dash-casing (e.g.,
pre-hooks,post-hooks,container-name) for configuration keys.pre-hooks: - command: [ "sleep", "5" ] os: [ "linux", "darwin" ] - command: [ "timeout", "5" ] os: [ "windows" ] - container-command: [ "echo", "foo" ] container-name: foo pod-prefix: bar post-hooks: - command: [ "echo", "foo" ]- Host-level commands: Executed on the machine running Skaffold using
Optimize in-cluster build performance with concurrency
mainBy default, Skaffold attempts to build all artifacts in parallel during an in-cluster build. If your cluster resources are limited, you can control the number of simultaneous builds using the
concurrencysetting.- Parallel builds (default): All artifacts are built at once.
- Sequential builds: Set
concurrency: 1to build artifacts one after another. - Controlled parallelism: Set
concurrencyto a value greater than1to limit the number of simultaneous builds.
Note: Even when builds run in parallel, Skaffold prints build logs in sequence to ensure readability.
build: cluster: concurrency: 1Access the Skaffold API via gRPC or HTTP
mainSkaffold provides an API that allows developers to retrieve information about the current state of the Skaffold process and exert fine-grained control over its execution. This API is exposed through two primary protocols:
- gRPC: Use the gRPC interface for high-performance, strongly-typed communication.
- HTTP: Use the HTTP interface (documented via Swagger/OpenAPI) for standard web-based integration.
Detailed design information regarding the API's purpose and architecture can be found in the Skaffold design documentation.