Coder Social home page Coder Social logo

kubectl-iexec's Introduction

Kubectl Interactive Exec

Summary

Kubectl-iexec is a plugin providing an interactive selector to exec into a running pod. For a search filter, the plugin will return a list of pods and containers that match, then perform a kubectl exec to the selection.

Notes:

Kubectl >= v1.12.0 is required for plugins to work

For more information on kuberctl plugins see documentation

Usage:

$ kubectl iexec --help

Kubectl-iexec is an interactive pod and container selector for `kubectl exec`

Arg[1] will act as a filter, any pods that match will be returned in a list
that the user can select from. Subsequent args make up the array of commands that
should be executed on the pod.

example:
kubectl iexec busybox /bin/sh

example:
kubectl iexec busybox cat /etc/hosts

Usage:
  iexec [pod filter] [remote command(s)] [flags]

Flags:
  -c, --container string   Container to search
  -h, --help               help for iexec
  --log-level string   log level (trace|debug|info|warn|error|fatal|panic)
  -x, --naked              Decolorize output
  -n, --namespace string   Namespace to search
  -v, --vim-mode            Vim Mode enabled
  -l, --label string        Label selector to filter pods

asciicast

Install:

To install the plugin, the binary simply needs to be somewhere on your path in the format kubectl-[plugin_name]. the simplest way to do this is to go get the package:

go get -u github.com/gabeduke/kubectl-iexec

Alternatively you may pull the binary from the releases page on Github:

Select OS

# Linux
OS=LINUX

# Mac
OS=DARWIN

Run:

# Get latest release
TAG=$(curl -s https://api.github.com/repos/gabeduke/kubectl-iexec/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")')

# Donwload and extract binary to /usr/local/bin
curl -LO https://github.com/gabeduke/kubectl-iexec/releases/download/${TAG}/kubectl-iexec_${TAG}_${OS:-Linux}_x86_64.tar.gz

mkdir -p /tmp/kubectl-iexec
tar -xzvf kubectl-iexec_${TAG}_${OS}_x86_64.tar.gz -C /tmp/kubectl-iexec
chmod +x /tmp/kubectl-iexec/kubectl-iexec

sudo mv /tmp/kubectl-iexec/kubectl-iexec /usr/local/bin

kubectl-iexec's People

Contributors

a5r0n avatar eminaktas avatar francoisdugard avatar gabeduke avatar mattn avatar soundmonster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

kubectl-iexec's Issues

kubectl-ilog?

I love iexec, it has helped me countless times to just get stuff done when debugging / building my cluster. Is there any chance you could be convinced to create something similar for kubectl log?
I have log aggregation and everything else up and running, but sometimes it's just quicker to get the data directly from the cli. I think something like ilog could help significantly in that respect.

The ultimate plugin would be a kubectl command wrapper where you do the fuzzy lookup for all entities and all commands, which obviously is a bit of a bigger challenge.
e.g. kubectl i get sts -o yaml prom would search for stateful sets matching prom and show a selection if there is any ambiguity before forwarding the command.

kubectl iexec is not prompting the pod names

Hi dear developers of kubectl-iexec,

I installed the krew on my macos system by following this documantation.

Then, I executed this command to install iexec: kubectl krew install iexec

In the iexec documentation, by calling kubectl iexec, it should print all the pod names in the current namespace and allow me to choose to exec in the selected pod. Instead of it is printing k iexec --help output.

Emin.Aktas ~ >> k iexec
Error: requires at least 1 arg(s), only received 0
Usage:
  iexec [pod filter] [remote command(s)] [flags]

Examples:

	# select from all pods in the namespace then run: 'kubectl exec sh'
	kubectl iexec 

	# select from all pods matching [busybox] then run: 'kubectl exec [pod_name] /bin/sh'
	kubectl iexec busybox

Compability with Teleport

I would be great to see the iexec plugin working with Teleport.

Whenever trying to connect proxied via Teleport, it does not move along.

❯ kubectl iexec --insecure-skip-tls-verify --log-level trace postfix /bin/bash
DEBU[0000] iexec config values...                        Naked=false Namespace=default Vim Mode=false containerFilter= podFilter=postfix remote command="[/bin/bash]"
DEBU[0000] total pods discovered...                      namespace=default pods=43
INFO[0000] Get all pods for podFilter...                 SearchFilter=postfix
INFO[0000] Found pod...                                  PodName=postfix-6b89f86fb-4b277 index=23
INFO[0000] Exec to pod...                                container=postfix namespace=default pod=postfix-6b89f86fb-4b277
DEBU[0000] Request                                       URL="https://teleport.<REDACTED>:3026/api/v1/namespaces/default/pods/postfix-6b89f86fb-4b277/exec?command=%2Fbin%2Fbash&container=postfix&stderr=true&stdin=true&stdout=true&tty=true"

Housekeeping

  • upgrade k8s version to 1.18
  • Use genericcliopts

Arm64 Support

Trying to install on an Apple M1 chip and getting:

failed to install plugin "iexec": plugin "iexec" does not offer installation for this platform

By default use the namespace configured in Kubernetes context

Thanks for writing the plugin. Currently, it works for me if I explicitly provide the namespace, otherwise, it just hangs. From the logs, it looks like the plugin is trying to fetch pod list info from all the namespaces which can be quite big and slow.

Flags:
      --all-namespaces             If present, tail across all namespaces. A specific namespace is ignored even if specified with --namespace.
  -n, --namespace string           Kubernetes namespace to use. Default to namespace configured in Kubernetes context

stern has the above options, which plays nicely with large k8s cluster.

revise the error message in case no running pods found

What I expect here is that something like no running pods found. We are already checking the err case, but not len(pods) == 0 in here.

Actual:

$ k get pods
NAME         READY   STATUS             RESTARTS   AGE
foo-1        0/1     ImagePullBackOff   0          15h
foo-2        0/1     ImagePullBackOff   0          26h
foo-3        0/1     ImagePullBackOff   0          175m

$ kubectl iexec foo --log-level trace
DEBU[0000] iexec config values...                        Naked=false Namespace=test Vim Mode=false containerFilter= podFilter=foo remote command="[/bin/sh]"
DEBU[0000] total pods discovered...                      namespace=test pods=0
INFO[0000] Get all pods for podFilter...                 SearchFilter=foo
FATA[0000] no pods found for filter: foo

Expected:

$ kubectl iexec foo
no running pods found

cc: @eminaktas

Documentation

There should be documentation for browsing (via go.pk.dev)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.