ko
: Easy Go Containersko
is a simple, fast container image builder for Go applications.
It's ideal for use cases where your image contains a single Go application without any/many dependencies on the OS base image (e.g., no cgo, no OS package dependencies).
ko
builds images by effectively executing go build
on your local machine, and as such doesn't require docker
to be installed. This can make it a good fit for lightweight CI/CD use cases.
ko
also includes support for simple YAML templating which makes it a powerful tool for Kubernetes applications (See below).
VERSION=TODO # choose the latest version
OS=Linux # or Darwin
ARCH=x86_64 # or arm64, i386, s390x
curl -L https://github.com/google/ko/releases/download/v${VERSION}/ko_${VERSION}_${OS}_${ARCH}.tar.gz | tar xzf - ko
chmod +x ./ko
brew install ko
With Go 1.16+, build and install the latest released version:
go install github.com/google/ko@latest
ko
depends on the authentication configured in your Docker config (typically ~/.docker/config.json
). If you can push an image with docker push
, you are already authenticated for ko
.
Since ko
doesn't require docker
, ko login
also provides a surface for logging in to a container image registry with a username and password, similar to docker login
.
ko
depends on an environment variable, KO_DOCKER_REPO
, to identify where it should push images that it builds. Typically this will be a remote registry, e.g.:
KO_DOCKER_REPO=gcr.io/my-project
, orKO_DOCKER_REPO=my-dockerhub-user
ko publish ./cmd/app
builds and pushes a container image, and prints the resulting image digest to stdout.
In this example, ./cmd/app
must be a package main
that defines func main()
.
ko publish ./cmd/app
...
gcr.io/my-project/app-099ba5bcefdead87f92606265fb99ac0@sha256:6e398316742b7aa4a93161dce4a23bc5c545700b862b43347b941000b112ec3e
Because the output of ko publish
is an image reference, you can easily pass it to other tools that expect to take an image reference:
To run the container:
docker run -p 8080:8080 $(ko publish ./cmd/app)
Or, for example, to deploy it to other services like Cloud Run:
gcloud run deploy --image=$(ko publish ./cmd/app)
Aside from KO_DOCKER_REPO
, you can configure ko
's behavior using a .ko.yaml
file. The location of this file can be overridden with KO_CONFIG_PATH
.
By default, ko
bases images on gcr.io/distroless/static:nonroot
. This is a small image that provides the bare necessities to run your Go binary.
You can override this base image in two ways:
ko
builds, add this line to your .ko.yaml
file:defaultBaseImage: registry.example.com/base/image
baseImageOverrides: github.com/my-user/my-repo/cmd/app: registry.example.com/base/for/app github.com/my-user/my-repo/cmd/foo: registry.example.com/base/for/foo
By default, ko
builds the binary with no additional build flags other than --trimpath
(depending on the Go version). You can replace the default build arguments by providing build flags and ldflags using a GoReleaser influenced builds
configuration section in your .ko.yaml
.
builds: - id: foo main: ./foobar/foo env: - GOPRIVATE=git.internal.example.com,source.developers.google.com flags: - -tags - netgo ldflags: - -s -w - -extldflags "-static" - -X main.version={{.Env.VERSION}} - id: bar main: ./foobar/bar/main.go env: - GOCACHE=/workspace/.gocache ldflags: - -s - -w
For the build, ko
will pick the entry based on the respective import path being used. It will be matched against the local path that is configured using dir
and main
. In the context of ko
, it is fine just to specify main
with the intended import path.
Please note: Even though the configuration section is similar to the GoReleaser builds
section, only the env
, flags
and ldflags
fields are currently supported. Also, the templating support is currently limited to environment variables only.
ko
provides a few different strategies for naming the image it pushes, to workaround certain registry limitations and user preferences:
Given KO_DOCKER_REPO=registry.example.com/repo
, by default, ko publish ./cmd/app
will produce an image named like registry.example.com/repo/app-<md5>
, which includes the MD5 hash of the full import path, to avoid collisions.
--preserve-import-path
(-P
) will include the entire importpath: registry.example.com/repo/github.com/my-user/my-repo/cmd/app
--base-import-paths
(-B
) will omit the MD5 portion: registry.example.com/repo/app
--bare
will only include the KO_DOCKER_REPO
: registry.example.com/repo
ko
is normally used to publish images to container image registries, identified by KO_DOCKER_REPO
.
ko
can also publish images to a local Docker daemon, if available, by setting KO_DOCKER_REPO=ko.local
, or by passing the --local
(-L
) flag.
Locally-published images can be used as a base image for other ko
images:
defaultBaseImage: ko.local/example/base/image
ko
can also publish images to a local KinD cluster, if available, by setting KO_DOCKER_REPO=kind.local
. By default this publishes to the default KinD cluster name (kind
). To publish to another KinD cluster, set KIND_CLUSTER_NAME=my-other-cluster
.
Because Go supports cross-compilation to other CPU architectures and operating systems, ko
excels at producing multi-platform images.
To build and push an image for all platforms supported by the configured base image, simply add --platform=all
. This will instruct ko
to look up all the supported platforms in the base image, execute GOOS=<os> GOARCH=<arch> GOARM=<variant> go build
for each platform, and produce a manifest list containing an image for each platform.
You can also select specific platforms, for example, --platform=linux/amd64,linux/arm64
ko
can also bundle static assets into the images it produces.
By convention, any contents of a directory named <importpath>/kodata/
will be bundled into the image, and the path where it's available in the image will be identified by the environment variable KO_DATA_PATH
.
As an example, you can bundle and serve static contents in your image:
cmd/
app/
main.go
kodata/
favicon.ico
index.html
Then, in your main.go
:
func main() { http.Handle("/", http.FileServer(http.Dir(os.Getenv("KO_DATA_PATH")))) log.Fatal(http.ListenAndServe(":8080", nil)) }
You can simulate ko
's behavior outside of the container image by setting the KO_DATA_PATH
environment variable yourself:
KO_DATA_PATH=cmd/app/kodata/ go run ./cmd/app
Tip: Symlinks in kodata
are followed and included as well. For example, you can include Git commit information in your image with:
ln -s -r .git/HEAD ./cmd/app/kodata/
Also note that http.FileServer
will not serve the Last-Modified
header (or validate If-Modified-Since
request headers) because ko
does not embed timestamps by default.
This can be supported by manually setting the KO_DATA_DATE_EPOCH
environment variable during build (See below).
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:
apiVersion: apps/v1 kind: Deployment metadata: name: my-deployment spec: replicas: 3 ... template: spec: containers: - name: my-app image: registry.example.com/my-app:v1.2.3
...which you apply to your cluster with kubectl apply
:
kubectl apply -f deployment.yaml
With ko
, you can instead reference your Go binary by its importpath, prefixed with ko://
:
... spec: containers: - name: my-app image: ko://github.com/my-user/my-repo/cmd/app
ko resolve
With this small change, running ko resolve -f deployment.yaml
will instruct ko
to:
ko://
prefix,ko://
-prefixed string, execute ko publish <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), for example:spec: containers: - name: my-app image: registry.example.com/github.com/my-user/my-repo/cmd/app@sha256:deadb33f...
The result can be redirected to a file, to distribute to others:
ko resolve -f config/ > release.yaml
Taken together, 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.
ko apply
To apply the resulting resolved YAML config, you can redirect the output of ko resolve
to kubectl apply
:
ko resolve -f config/ | kubectl apply -f -
Since this is a relatively common use case, the same functionality is available using ko apply
:
ko apply -f config/
NB: This requires that kubectl
is available.
ko delete
To teardown resources applied using ko apply
, you can run ko delete
:
ko delete -f config/
This is purely a convenient alias for kubectl delete
, and doesn't perform any builds, or delete any previously built images.
ldflags
?Using -ldflags is a common way to embed version info in go binaries (In fact, we do this for ko
!). Unfortunately, because ko
wraps go build
, it's not possible to use this flag directly; however, you can use the GOFLAGS
environment variable instead:
GOFLAGS="-ldflags=-X=main.version=1.2.3" ko publish .
ldflags
?Currently, there is a limitation that does not allow to set multiple arguments in ldflags
using GOFLAGS
. Using -ldflags
multiple times also does not work. In this use case, it works best to use the builds
section in the .ko.yaml
file.
In order to support reproducible builds, ko
doesn't embed timestamps in the images it produces by default.
However, ko
does respect the SOURCE_DATE_EPOCH
environment variable, which will set the container image's timestamp accordingly.
Similarly, the KO_DATA_DATE_EPOCH
environment variable can be used to set the modtime timestamp of the files in KO_DATA_PATH
.
For example, you can set the container image's timestamp to the current timestamp by executing:
export SOURCE_DATE_EPOCH=$(date +%s)
or set the timestamp of the files in KO_DATA_PATH
to the latest git commit's timestamp with:
export KO_DATA_DATE_EPOCH=$(git log -1 --format='%ct')
Yes, but support for Windows containers is new, experimental, and tenuous. Be prepared to file bugs. ��
The default base image does not provide a Windows image. You can try out building a Windows container image by setting the base image to a Windows base image and building with --platform=windows/amd64
or --platform=all
:
For example, to build a Windows container image for ko
, from within this repo:
KO_DEFAULTBASEIMAGE=mcr.microsoft.com/windows/nanoserver:1809 ko publish ./ --platform=windows/amd64
kodata
are ignored when building Windows images; only regular files and directories will be included in the Windows image.Yes! Set the environment variable GGCR_EXPERIMENT_ESTARGZ=1
to produce eStargz-optimized images.
ko
support autocompletion?Yes! ko completion
generates a Bash completion script, which you can add to your bash_completion
directory:
ko completion > /usr/local/etc/bash_completion.d/ko
Or, you can source it directly:
source <(ko completion)
ko
work with Kustomize?Yes! ko resolve -f -
will read and process input from stdin, so you can have ko
easily process the output of the kustomize
command.
kustomize build config | ko resolve -f -
ko
work with OpenShift Internal Registry?Yes! Follow these steps:
$HOME/.docker/config.json
:oc registry login --to=$HOME/.docker/config.json
ko-images
KO_DOCKER_REPO
to publish images to the internal registry.export KO_DOCKER_REPO=$(oc registry info --public)/ko-images
This work is based heavily on learnings from having built the Docker and Kubernetes support for Bazel. That work was presented here.
Questions? Comments? Ideas? Come discuss ko
with us in the #ko-project
channel on the Kubernetes Slack! See you there!
解决方法是更新 setuptools 和 pip: pip install --upgrade setuptools python -m pip install --upgrade pip
错误日志: $ make make -C /lib/modules/4.15.0-58-generic/build SUBDIRS=/xxxx/3-netlink modules make[1]: Entering directory '/usr/src/linux-headers-4.15.0-58-generic' Makefile:986: "Cannot use CONFIG_STACK_
一、makefile脚本 KERN_DIR = ../../linux-4.9.84/ ARCH := arm CROSS_COMPILE := arm-buildroot-linux-uclibcgnueabihf- EXTRA_CFLAGS += -Werror MODULE_NAME = alex_main EXTRA_CFLAGS += -I$(PWD)/include/kernel -
一. kbuild系统主要涉及的几个文件 文件名 作用 Makefile 内核源代码顶层目录的Makefile文件 scripts/Makefile.build 通常在进行递归make时会用到的Makefile文件 scripts/Makefile.host 如果需要生成可执行文件时会用到的文件。例如:在编译内核之前需要配置内核,此时会编译生成配置程序,在这个过程中会用到这个文件 scripts/
假设模块的源文件为hello.c,源码如下: #include #include #include #include #include #define HELLO_MAJOR 231 #define DEVICE_NAME "HelloModule" static int hello_open(struct inode *inode, struct file *file) { printk(KER
以两个C文件为例: 将本该被分别编译成adc_device.ko和adc_driver.ko的adc_device.c、adc_driver.c编译成一个ko文件! 采用方法: 第一步、修改C文件 1、去掉adc_device.c文件里module_init(xxx)、module_exit(yyy)中xxx、yyy 函数原型的关键字static 2、注销adc_device.c文件里module
导语:经过确认,我用ubuntu20.04安装完nvidia-docker之后再安装nvidia驱动就会出现问题,重启也没用。 整理了一下,得先装cuda,然后再装nvidia-docker2才没问题。 #!/bin/bash localpath=$( cd "$(dirname "$0")" pwd ) #显色信息提示 blue() { echo -e "\033[34m $(da
执行shell脚本报错 -bash: ./build: /bin/bash^M: bad interpreter: No such file or directory 解决方法: vim x.sh进入x.sh后, 在底部模式下, 执行 :set fileformat=unix后执行 :x或 :wq保存修改。 然后就可以执行./x.sh运行脚本了
平台:RK3229 Android:7.1 問題:執行./build_wifi_ko.sh 出現 FATAL: modpost: GPL-incompatible module vcodec_service.ko uses GPL-only symbol 'platform_driver_unregister' 解決:到kernel\arch\arm=mach-rockchip\vcodec
ko 是一个简单、快速的 Go 应用程序容器镜像构建器。它非常适用于这样的情况:你的镜像包含一个单一的 Go 应用程序,而没有任何/许多对操作系统基础镜像的依赖(例如,没有 cgo,没有操作系统包的依赖)。 ko 通过在你的本地机器上有效执行go build来构建镜像,因此不需要安装docker。这使得它很适合于轻量级的CI/CD用例。 ko还包括对简单YAML模板的支持,这使得它成为Kubern
问题内容: 当我打开JMeter仪表板时,我可以在列中看到成功,而在列中看到失败。根据城市词典 KO等于OK “ KO”等价于表示“ OK”的字母的含义和缩写 还是法国的非正式缩写? 我注意到,法语和意大利语非正式交流中的首字母缩写词KO意味着“不好” 我看到了有关将KO标签更改为失败的不同问题。 为什么JMeter将错误称为,在性能测试中还有其他含义吗?还是在积极思考失败也可以的地方? 问题答案
本文向大家介绍基于KO+BootStrap+MVC实现的分页控件代码分享,包括了基于KO+BootStrap+MVC实现的分页控件代码分享的使用技巧和注意事项,需要的朋友参考一下 JS: HTML: 以上所述是小编给大家介绍的基于KO+BootStrap+MVC实现的分页控件代码分享,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对呐喊教程网站的支持!
我在我的pod上配置了一个带有二进制执行检查的readinessProbe,它连接到我正在运行的服务器(在同一个容器中),并检索一些健康信息(比如准备好流量)。 配置为readinessProbe,二进制文件无法联系我的服务器并获得所需的信息。它通过TCP套接字连接。但是当我将其配置为livenessProbe时,它可以正常工作。 配置为了让它工作,我只将类型从readinessProbe更改为l