Ship your first app (ko)
This builds a small Go web server with ko (no Dockerfile), pushes it to your registry, and serves it over HTTPS.
It assumes:
- You can reach your cluster with
kubectl(see the kubectl quickstart). - You’ve set up GHCR credentials: a local push login and the
ghcrpull secret in thedemonamespace (see Set up GHCR credentials). - The optional ingress bundle is installed, for HTTPS (see Expose a service with Ingress).
- You have Go and
koinstalled locally.
Write the app
Section titled “Write the app”mkdir hello && cd hellogo mod init example.com/hellocat <<'EOF' > main.gopackage main
import ( "fmt" "log" "net/http")
func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "hello from skube - ko") }) log.Fatal(http.ListenAndServe(":8080", nil))}EOFPoint ko at your registry
Section titled “Point ko at your registry”You’re already logged in to ghcr.io from the credentials guide, so ko just
needs to know which repo to push to:
export KO_DOCKER_REPO=ghcr.io/<github-username>Write the manifest
Section titled “Write the manifest”The ko:// image reference tells ko to build main.go and substitute the
pushed image:
cat <<'EOF' > deploy.yamlapiVersion: apps/v1kind: Deploymentmetadata: name: hello namespace: demospec: replicas: 1 selector: matchLabels: app: hello template: metadata: labels: app: hello spec: containers: - name: hello image: ko://example.com/hello ports: - containerPort: 8080---apiVersion: v1kind: Servicemetadata: name: hello namespace: demospec: selector: app: hello ports: - port: 80 targetPort: 8080---apiVersion: networking.k8s.io/v1kind: Ingressmetadata: name: hello namespace: demo annotations: cert-manager.io/cluster-issuer: letsencrypt-prodspec: ingressClassName: traefik tls: - hosts: - hello.example.com secretName: hello-tls rules: - host: hello.example.com http: paths: - path: / pathType: Prefix backend: service: name: hello port: number: 80EOFBuild, push, deploy
Section titled “Build, push, deploy”ko apply -f deploy.yamlko compiles the app, pushes the image to ghcr.io/<you>/hello, rewrites the
ko:// reference, and applies the manifest. The pushed package is private by
default, which is why the cluster needs the ghcr pull secret from the previous
guide.
Verify
Section titled “Verify”kubectl get certificate hello-tls -n demo -wOnce READY is True:
curl https://hello.example.comYou should get back hello from skube - ko.
Clean up
Section titled “Clean up”kubectl delete namespace demo