Skip to content

engineerd/kube-exec

Folders and files

NameName
Last commit message
Last commit date

Latest commit

b4411f2 · Feb 18, 2019

History

54 Commits
Feb 18, 2019
Feb 18, 2019
Feb 18, 2019
Feb 18, 2019
Feb 18, 2019
Dec 17, 2018
Dec 17, 2018
Feb 18, 2019
Dec 17, 2018
Feb 18, 2019
Jan 30, 2018
Jul 27, 2018

Repository files navigation

kube-exec

CircleCI Go Report Card Documentation

kube-exec is a library similar to os/exec that allows you to run commands in a Kubernetes pod, as if that command was executed locally.

It is inspired from go-dexec by ahmetb, 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 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

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.Stdout

err := cmd.Run()
if err != nil {
	log.Fatalf("error: %v", err)
}

Here's a list of full examples you can find in this repo: