Skip to content

Quickstart

Pre requisites:

In order to work with these tools you need:

  • Buildtools installed (of course)
  • Docker - read more about options here
  • Kubernetes - if you're using for example Docker for Mac Kubernetes can easily be enabled.

In this example we will build, push and deploy a sample Go project.

Create a Git repository and add a single main package with a http server:

mkdir quickstart
cd quickstart
git init
// main.go
package main

import (
    "fmt"
    "net/http"
)

func main() {
    http.HandleFunc("/", HelloServer)
    http.ListenAndServe(":8080", nil)
}

func HelloServer(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hello, %s!", r.URL.Path[1:])
}

Add a Dockerfile describing how to build your code:

# Dockerfile
FROM golang:1.15 as build
WORKDIR /build
ADD . /build

RUN GOOS=linux GOARCH=amd64 go build main.go

FROM debian:buster-slim
COPY --from=build /build/main /
CMD ["/main"]

Add the files to source control and commit:

git add .
git commit -m "Init"
Build the docker image:

build

After the build completes you should see output like

...
Successfully tagged noregistry/quickstart:latest

Try to run your newly built docker image:

docker run --rm -p 8080:8080 noregistry/quickstart:latest
and try to access it:
curl localhost:8080/buildtools
You should see a response like:
Hello, buildtools!

Let's try to deploy it to our local Kubernetes cluster, in order for this to work we need a Kubernetes descriptor file. Create a k8s folder and a file deploy.yaml:

# k8s/deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: quickstart
  annotations:
    kubernetes.io/change-cause: "${TIMESTAMP} Deployed commit id: ${COMMIT}"
  labels:
    app: quickstart
spec:
  replicas: 1
  selector:
    matchLabels:
      app: quickstart
  template:
    metadata:
      labels:
        app: quickstart
    spec:
      containers:
      - name: quickstart
        imagePullPolicy: IfNotPresent
        image: ${IMAGE}

This will create Kubernetes deployment, basically starting your application inside the Kubernetes cluster.

deploy --context docker-desktop
kubectl --context docker-desktop get pods

quickstart-b4c5bc467-lqk6r      1/1     Running        0          3s