Skaffold

Skaffold Demo

Skaffold is a really easy tool to use most of which can be done just by following the simple instructions on the github site: https://github.com/GoogleContainerTools/skaffold#getting-started-with-local-tooling

Prerequisites

I’m doing development locally on my mac with Docker for mac - Kubernetes

Install skaffold on mac

brew install skaffold

Make sure your connected to a cluster

kubectl get ns

Get to work

Lets clone an app to work with

git clone https://github.com/GoogleContainerTools/skaffold
cd skaffold/examples/getting-started

Edit skaffold.yaml Replace k8s-project with your GCP project ID

Run Skaffold

skaffold dev

Make a change

Open main.go and change the Hello World to something else

package main

import (
	"fmt"
	"time"
)

func main() {
	for {
		fmt.Println("Skaffold Rulz!")

		time.Sleep(time.Second * 1)
	}
}

It’s that simple. When you save the file skaffold will automatically:

Build your image

Push the image if deploying remotely Deploy your app to kubernetes

Bonus: Skaffold will automatically delete resources when it’s stopped (ctrl + c) Skaffold only updates resources that have changed, helpful in a microservice project

Notes: When my context points to local kubernetes skaffold ignores my cloud tools such as push to gcr.io When my context points to a remote cluster it trys to push to the repo listed on the image. For gcr.io I needed to configure it for docker with:

gcloud auth configure-docker

To use cloud builder i needed to add…

build:
 artifacts:
 - imageName: gcr.io/crg-gcp/skaffold-example
 googleCloudBuild:
   projectId: crg-gcp

Also make sure your gcloud config is set to the right project I was on some other project and couldn’t pull from my crg-gcp repo <sigh>