You could stop at just building and pushing images.
But, because building images is so easy with
ko, and because building with
ko only requires a string importpath to identify the image, we can integrate
this with YAML generation to make Kubernetes use cases much simpler.
Traditionally, you might have a Kubernetes deployment, defined in a YAML file, that runs an image:
...which you apply to your cluster with
ko, you can instead reference your Go binary by its importpath, prefixed
With this small change, running
ko resolve -f deployment.yaml will instruct
- scan the YAML file(s) for values with the
- for each unique
ko://-prefixed string, execute
ko build <importpath>to build and push an image,
ko://-prefixed string(s) in the input YAML with the fully-specified image reference of the built image(s), as above.
- Print the resulting resolved YAML to stdout.
The result can be redirected to a file, to distribute to others:
ko resolve aims to make packaging, pushing, and referencing
container images an invisible implementation detail of your Kubernetes
deployment, and let you focus on writing code in Go.
To apply the resulting resolved YAML config, you can redirect the output of
ko resolve to
Since this is a relatively common use case, the same functionality is available
Also, any flags passed after
-- are passed to
kubectl apply directly, for example to specify context and kubeconfig:
NB: This requires that
kubectl is available.
To teardown resources applied using
ko apply, you can run
This is purely a convenient alias for
kubectl delete, and doesn't perform any
builds, or delete any previously built images.