Getting Started

This document showcases how to get started with Skaffold using Docker and Kubernetes command-line tool, kubectl. Aside from Docker and kubectl, Skaffold also supports a variety of other tools and workflows; see How-to Guides and Tutorials for more information.

In this quickstart, you will:

  • Install Skaffold,
  • Download a sample go app,
  • Use skaffold dev to build and deploy your app every time your code changes,
  • Use skaffold run to build and deploy your app once, on demand.

Before you begin

Installing Skaffold

Stable binary

For the latest stable release download and place it in your PATH:

https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64

Run these commands to download and place the binary in your /usr/local/bin folder:

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

Latest bleeding edge binary

For the latest bleeding edge build, download and place it in your PATH:

https://storage.googleapis.com/skaffold/builds/latest/skaffold-linux-amd64

Run these commands to download and place the binary in your /usr/local/bin folder:

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

Homebrew

brew install skaffold

Stable binary

For the latest stable release download and place it in your PATH:

https://storage.googleapis.com/skaffold/releases/latest/skaffold-darwin-amd64

Run these commands to download and place the binary in your /usr/local/bin folder:

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

Bleeding edge binary

For the latest bleeding edge build, download and place it in your PATH:

https://storage.googleapis.com/skaffold/builds/latest/skaffold-darwin-amd64

Run these commands to download and place the binary in your /usr/local/bin folder:

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

Chocolatey

choco install skaffold

Stable binary

For the latest stable release download and place it in your PATH as skaffold.exe:

https://storage.googleapis.com/skaffold/releases/latest/skaffold-windows-amd64.exe

Bleeding edge binary

For the latest bleeding edge build, download and place it in your PATH as skaffold.exe:

https://storage.googleapis.com/skaffold/builds/latest/skaffold-windows-amd64.exe

Stable binary

For the latest stable release, you can use:

docker run gcr.io/k8s-skaffold/skaffold:latest skaffold <command>

Bleeding edge binary

For the latest bleeding edge build:

docker run gcr.io/k8s-skaffold/skaffold:edge skaffold <command>

Downloading the sample app

  1. Clone the Skaffold repository:

    git clone https://github.com/GoogleContainerTools/skaffold
  2. Change to the examples/getting-started directory.

    cd examples/getting-started

skaffold dev: Build and deploy your app every time your code changes

Run skaffold dev --default-repo <myrepo> to build and deploy your app continuously. The --default-repo functionality enables pushing images to your own repository instead of the default gcr.io/k8s-skaffold repo. You should see some outputs similar to the following entries:

Starting build...
Found [minikube] context, using local docker daemon.
Sending build context to Docker daemon  6.144kB
Step 1/5 : FROM golang:1.9.4-alpine3.7
 ---> fb6e10bf973b
Step 2/5 : WORKDIR /go/src/github.com/GoogleContainerTools/skaffold/examples/getting-started
 ---> Using cache
 ---> e9d19a54595b
Step 3/5 : CMD ./app
 ---> Using cache
 ---> 154b6512c4d9
Step 4/5 : COPY main.go .
 ---> Using cache
 ---> e097086e73a7
Step 5/5 : RUN go build -o app main.go
 ---> Using cache
 ---> 9c4622e8f0e7
Successfully built 9c4622e8f0e7
Successfully tagged 930080f0965230e824a79b9e7eccffbd:latest
Successfully tagged <myrepo>/gcr.io/k8s-skaffold/skaffold-example:9c4622e8f0e7b5549a61a503bf73366a9cf7f7512aa8e9d64f3327a3c7fded1b
Build complete in 657.426821ms
Starting deploy...
Deploying k8s-pod.yaml...
Deploy complete in 173.770268ms
[getting-started] Hello world!

skaffold dev monitors your code repository and perform a Skaffold workflow every time a change is detected. skaffold.yaml provides specifications of the workflow, which, in this example, is

  • Building a Docker image from the source using the Dockerfile
  • Tagging the Docker image with the Sha256 Hash of its contents
  • (If you use a hosted Kubernetes solution) Pushing the Docker image to the external Docker image registry
  • Updating the Kubernetes manifest, k8s-pod.yaml, to use the image built previously
  • Deploying the Kubernetes manifest using kubectl apply -f
  • Streaming the logs back from the deployed app

Let’s re-trigger the workflow just by a single code change! Update main.go as follows:

package main

import (
	"fmt"
	"time"
)

func main() {
	for {
		fmt.Println("Hello Skaffold!")
		time.Sleep(time.Second * 1)
	}
}

The moment you save the file, Skaffold will repeat the workflow described in skaffold.yaml and eventually re-deploy your application. Once the pipeline is completed, you should see updated outputs in the terminal:

[getting-started] Hello Skaffold!

skaffold run: Build and deploy your app once, on demand

If you prefer building and deploying once at a time, run command skaffold run. Skaffold will perform the workflow described in skaffold.yaml exactly once.

What’s next

For more in-depth topics of Skaffold, explore Skaffold Concepts: Configuration, Skaffold Concepts: Workflow, and Skaffold Concepts: Architecture.

To learn more about how Skaffold builds, tags, and deploys your app, see the How-to Guides on using Builders, Taggers, and Deployers.

Skaffold Tutorials details some of the common use cases of Skaffold.