Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/engineerd/kube-exec
Lightweight Golang package for executing commands in remote Kubernetes pods
https://github.com/engineerd/kube-exec
Last synced: about 2 months ago
JSON representation
Lightweight Golang package for executing commands in remote Kubernetes pods
- Host: GitHub
- URL: https://github.com/engineerd/kube-exec
- Owner: engineerd
- License: mit
- Created: 2018-01-06T13:50:49.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-22T06:24:14.000Z (almost 6 years ago)
- Last Synced: 2024-08-01T06:20:55.670Z (5 months ago)
- Language: Go
- Homepage: https://engineerd.github.io/kube-exec/introduction/
- Size: 511 KB
- Stars: 93
- Watchers: 2
- Forks: 7
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
kube-exec
=========[![CircleCI](https://circleci.com/gh/engineerd/kube-exec/tree/master.svg?style=shield&circle-token=13a8324e6b860dc9158a67d0102920047b5c1144)](https://circleci.com/gh/engineerd/kube-exec)
[![Go Report Card](https://goreportcard.com/badge/github.com/engineerd/kube-exec)](https://goreportcard.com/report/github.com/engineerd/kube-exec)
[![Documentation](https://godoc.org/github.com/engineerd/kube-exec?status.svg)](https://godoc.org/github.com/engineerd/kube-exec)`kube-exec` is a library similar to [`os/exec`][1] that allows you to run commands in a Kubernetes pod, as if that command was executed locally.
> It is inspired from [`go-dexec`][2] by [ahmetb][3], which does the same thing, but for a Docker engine.The interface of the package is similar to `os/exec`, and essentially this:
- creates a new pod in Kubernetes based on a user-specified image
- waits for the pod to be in [`Running`](https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/) state
- attaches to the pod and allows you to stream data to the pod through `stdin`, and from the pod back to the program through `stdout` and `stderr`How to use it
-------------```go
cfg := kube.Config{
Kubeconfig: os.Getenv("KUBECONFIG"),
Image: "ubuntu",
Name: "kube-example",
Namespace: "default",
}cmd := kube.Command(cfg, "/bin/sh", "-c", "sleep 2; echo Running from Kubernetes pod;")
cmd.Stdout = os.Stdouterr := cmd.Run()
if err != nil {
log.Fatalf("error: %v", err)
}
```Here's a list of full examples you can find in this repo:
- [simple hello example](/examples/hello/main.go)
- [pass `stdin` to the pod](/examples/stdin/main.go)
- [pass Kubernetes secrets as environment variables](/examples/secrets/main.go)[1]: https://golang.org/pkg/os/exec
[2]: https://github.com/ahmetb/go-dexec
[3]: https://twitter.com/ahmetb[4]: /examples/main.go