What is Skaffold?
Skaffold is an open source command line Continuous Development (CD) tool, which has been released earlier this year by Google. It helps developers to develop Cloud Native applications, which do not require a server-side component on your Kubernetes cluster and have pluggable architecture. This allows you to choose the tools in the developer workflow that best suit your needs. It has gained popularity in a short period of time among the community, and has been well adopted by other CI/CD tools - such as JenkinsX, which uses Skaffold to do Docker image building.
As of now Skaffold works along with following build and release tools:
The community is also working on:
Local Development with Skaffold
Skaffold Installation
Assuming you already have these prerequisites:
- Docker
- Local Kubernetes installation (Minikube/ Docker for Windows/Mac)
Download and install latest Skaffold binary from GitHub:
curl -Lo skaffold \
https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64
chmod +x skaffold
sudo mv skaffold /usr/local/bin
Getting started with Skaffold
To start you would place a Skaffold config file in the root directory along with your source code, Docker file and Kubernetes manifests. Then you run skaffold dev
, which will trigger the Docker build and tag locally, and kubectl apply
to your local Kubernetes cluster to deploy your application. Skaffold will be watching your source directory for changes and continuously building and deploying when changes are detected, based on your config.
Or you can simply run skaffold run
to skip the continuous deployment and just build and deploy your application on your Kubernetes cluster.
Once you have installed Skaffold, place the following files in a directory (change Docker image details in k8s-manifest.yaml
and skaffold.yaml
) and run:
skaffold dev .
main.go
:
package main
import (
"fmt"
"time"
)
func main() {
for {
fmt.Println(""Hello world!"")
time.Sleep(time.Second * 1)
}
}
Dockerfile
:
FROM golang:1.10.1-alpine3.7 as builder
COPY main.go .
RUN go build -o /app main.go
FROM alpine:3.7
CMD ["./app"]
COPY --from=builder /app .
Manifests:
# k8s-manifest.yaml
apiVersion: v1
kind: Pod
metadata:
name: getting-started
spec:
containers:
- name: getting-started
image: <your docker registry>/lw-skaffold-demo
---
# skaffold.yaml
apiVersion: skaffold/v1alpha2
kind: Config
build:
artifacts:
- imageName: <your docker registry>/lw-skaffold-demo
deploy:
kubectl:
manifests:
- k8s-*
Then make some changes in main.go and save. The new version (with changes) of your application will be built and deployed automatically by Skaffold on Kubernetes cluster, as well as streaming hot deployment logs.
DevOps Engineer Final Thoughts on Skaffold
With Skaffold, developers can perform hot deployment and mirror the the production deployment easily in their local or remote Kubernetes clusters. By having a local automated development + deployment workflow with Skaffold and Kubernetes, you can save time when developing and produce quality code. It will doubtless be a great help for developers who love Kubernetes, and I can see it being invaluable in the Kube community.