Difficulty: intermediate
Estimated Time: 20 minutes

In this scenario you'll see how Skaffold helps when you're developing Go applications that will run in Kubernetes.

Congratulations, you've finished this scenario!

Running on your laptop

If you would like to try running Skaffold on your laptop, you can install it as described in the documentation.


Step 1 of 3

Write a simple Go application

Start with a very simple app that writes a line to stdout every few seconds. When this app is deployed in a Kubernetes pod, you will be able to see this output as the pod's log output.

package main

import (

func main() {
    for {

Multistage build Dockerfile

# First stage: start with a Golang base image
FROM golang:1.12-alpine3.10

# Move to the directory where the source code will live
WORKDIR /go/src/hello

# Copy the source code into the current directory
COPY hello.go .

# Get any dependencies, and compile the code
RUN CGO_ENABLED=0 go get -v ./...

# Second stage: start from an empty base image
FROM scratch

# Copy the binary from the first stage
COPY --from=0 /go/bin/hello /

# Tell Docker what executable to run by default when starting this container
ENTRYPOINT ["/hello"]

Build this image and check that it works.

docker build -t hello .

docker run -t hello

This should log output to the screen on a regular basis.

Stop this container from a second terminal.

docker stop $(docker ps --filter ancestor=hello -q)

  • See the Docker documentation for more information about filtering the results from docker ps
  • The -q parameter returns just the container ID, which can then be passed to the docker stop command.

Next step

We have a very simple application that we can run in a container. Now let's get Skaffold to run it under Kubernetes.