Build

Skaffold has native support for several different tools for building images:

The build section in the Skaffold configuration file, skaffold.yaml, controls how artifacts are built. To use a specific tool for building artifacts, add the value representing the tool and options for using that tool to the build section.

For a detailed discussion on Skaffold Configuration, see skaffold.yaml References.

Skaffold supports building artifacts in following execution contexts:

  1. Local
  2. In Cluster
  3. Remotely on Google Cloud Build.

Local Build

Local build execution is the default execution context. Skaffold will use the build tools locally installed on your machine to execute the build.

Configuration

To configure the local execution explicitly, add build type local to the build section of skaffold.yaml

build:
  local:
    ...
Option Description Default
push should images be pushed to a registry. If not specified, images are pushed only if the current Kubernetes context connects to a remote cluster.
useDockerCLI use docker command-line interface instead of Docker Engine APIs. false
useBuildkit use BuildKit to build Docker images. false

If you are deploying to local cluster, you can additional set push to false to speed up builds.

In Cluster Build

Skaffold supports building in cluster via Kaniko or Custom Build Script.

Configuration

To configure in-cluster Build, add build type cluster to the build section of skaffold.yaml.

build:
  cluster:
    ...

The following options can optionally be configured:

Option Description Default
HTTP_PROXY for kaniko pod.
HTTPS_PROXY for kaniko pod.
pullSecret path to the Google Cloud service account secret key file.
pullSecretName name of the Kubernetes secret for pulling the files from the build context and pushing the final image. If given, the secret needs to contain the Google Cloud service account secret key under the key kaniko-secret. kaniko-secret
pullSecretMountPath path the pull secret will be mounted at within the running container.
namespace Kubernetes namespace. Defaults to current namespace in Kubernetes configuration.
timeout amount of time (in seconds) that this build is allowed to run. Defaults to 20 minutes (20m).
dockerConfig describes how to mount the local Docker configuration into a pod.
resources define the resource requirements for the kaniko pod.
concurrency how many artifacts can be built concurrently. 0 means “no-limit” Defaults to 0.

Remotely on Google Cloud Build

Skaffold supports building remotely with Google Cloud Build.

Google Cloud Build is a Google Cloud Platform service that executes your builds using Google infrastructure. To get started with Google Build, see Cloud Build Quickstart.

Skaffold can automatically connect to Cloud Build, and run your builds with it. After Cloud Build finishes building your artifacts, they will be saved to the specified remote registry, such as Google Container Registry.

Skaffold Google Cloud Build process differs from the gcloud command gcloud builds submit. Skaffold will create a list of dependent files and submit a tar file to GCB. It will then generate a single step cloudbuild.yaml and will start the building process. Skaffold does not honor .gitignore or .gcloudignore exclusions. If you need to ignore files use .dockerignore. Any cloudbuild.yaml found will not be used in the build process.

Configuration

To use Cloud Build, add build type googleCloudBuild to the build section of skaffold.yaml.

build:
  googleCloudBuild:
    ...

The following options can optionally be configured:

Option Description Default
projectId ID of your Cloud Platform Project. If it is not provided, Skaffold will guess it from the image name. For example, given the artifact image name gcr.io/myproject/image, Skaffold will use the myproject GCP project.
diskSizeGb disk size of the VM that runs the build. See Cloud Build Reference.
machineType type of the VM that runs the build. See Cloud Build Reference.
timeout amount of time (in seconds) that this build should be allowed to run. See Cloud Build Reference.
dockerImage image that runs a Docker build. See Cloud Builders. gcr.io/cloud-builders/docker
kanikoImage image that runs a Kaniko build. See Cloud Builders. gcr.io/kaniko-project/executor
mavenImage image that runs a Maven build. See Cloud Builders. gcr.io/cloud-builders/mvn
gradleImage image that runs a Gradle build. See Cloud Builders. gcr.io/cloud-builders/gradle
concurrency how many artifacts can be built concurrently. 0 means “no-limit” Defaults to 0.

Skaffold currently supports Docker and Jib Google Cloud Builders.

Last modified November 7, 2019: [Doc] Buildpacks (73d91f1a0)