While exploring, I came across ko tool by google & found interesting since it buids and deploy golang applications to kubernetes easily. This post is for minikube only since I am focussing on local development.

Pre-Flight Checks


go get github.com/google/go-containerregistry/cmd/ko

That’s it :)

eval $(minikube docker-env)

Let’s do it


package main

import (
	"fmt"
	"log"
	"net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Hi there")
}

func main() {
	http.HandleFunc("/", handler)
	log.Fatal(http.ListenAndServe(":8080", nil))
}
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: hello-world
spec:
  selector:
    matchLabels:
      foo: bar
  replicas: 1
  template:
    metadata:
      labels:
        foo: bar
    spec:
      containers:
      - name: hello-world
        # This is the import path for the Go binary to build and run.
        image: github.com/surajnarwade/webapp
        ports:
        - containerPort: 8080
kubectl expose deployment hello-world --type=NodePort
ko apply -L -f config.yml

-L indicates publishing images locally

What happens behind the scene ?



Reference:



Happy Hacking :)