Code Monkey home page Code Monkey logo

kube-prompt's Introduction

kube-prompt

Software License Go Report Card

An interactive kubernetes client featuring auto-complete using go-prompt.

demo

kube-prompt accepts the same commands as the kubectl, except you don't need to provide the kubectl prefix. So it doesn't require the additional cost to use this cli.

And you can integrate other commands via pipe (|).

>>> get pod | grep web
web-1144924021-2spbr        1/1     Running     4       25d
web-1144924021-5r1fg        1/1     Running     4       25d
web-1144924021-pqmfq        1/1     Running     4       25d

Installation

Downloading standalone binary

Binaries are available from github release.

macOS (darwin) - amd64
wget https://github.com/c-bata/kube-prompt/releases/download/v1.0.11/kube-prompt_v1.0.11_darwin_amd64.zip
unzip kube-prompt_v1.0.11_darwin_amd64.zip
chmod +x kube-prompt
sudo mv ./kube-prompt /usr/local/bin/kube-prompt
Linux - amd64
wget https://github.com/c-bata/kube-prompt/releases/download/v1.0.11/kube-prompt_v1.0.11_linux_amd64.zip
unzip kube-prompt_v1.0.11_linux_amd64.zip
chmod +x kube-prompt
sudo mv ./kube-prompt /usr/local/bin/kube-prompt
Linux - i386
wget https://github.com/c-bata/kube-prompt/releases/download/v1.0.11/kube-prompt_v1.0.11_linux_386.zip
unzip kube-prompt_v1.0.11_linux_386.zip
chmod +x kube-prompt
sudo mv ./kube-prompt /usr/local/bin/kube-prompt
Linux - arm64
wget https://github.com/c-bata/kube-prompt/releases/download/v1.0.11/kube-prompt_v1.0.11_linux_arm64.zip
unzip kube-prompt_v1.0.11_linux_arm64.zip
chmod +x kube-prompt
sudo mv ./kube-prompt /usr/local/bin/kube-prompt

Using Homebrew (macOS)

$ brew install c-bata/kube-prompt/kube-prompt

Arch Linux

An unofficial AUR package kube-prompt is available. Install instructions can be found on the Arch wiki.

Building from source

$ GO111MODULE=on go build .

To create a multi-platform binary, use the cross command via make:

$ make cross

Similar projects

Goal

Hopefully support following commands enough to operate kubernetes.

  • get Display one or many resources
  • describe Show details of a specific resource or group of resources
  • create Create a resource by filename or stdin
  • replace Replace a resource by filename or stdin.
  • patch Update field(s) of a resource using strategic merge patch.
  • delete Delete resources by filenames, stdin, resources and names, or by resources and label selector.
  • edit Edit a resource on the server
  • apply Apply a configuration to a resource by filename or stdin
  • namespace SUPERSEDED: Set and view the current Kubernetes namespace
  • logs Print the logs for a container in a pod.
  • rolling-update Perform a rolling update of the given ReplicationController.
  • scale Set a new size for a Deployment, ReplicaSet, Replication Controller, or Job.
  • cordon Mark node as unschedulable
  • drain Drain node in preparation for maintenance
  • uncordon Mark node as schedulable
  • attach Attach to a running container.
  • exec Execute a command in a container.
  • port-forward Forward one or more local ports to a pod.
  • proxy Run a proxy to the Kubernetes API server
  • run Run a particular image on the cluster.
  • expose Take a replication controller, service, or pod and expose it as a new Kubernetes Service
  • autoscale Auto-scale a Deployment, ReplicaSet, or ReplicationController
  • rollout rollout manages a deployment
  • label Update the labels on a resource
  • annotate Update the annotations on a resource
  • config config modifies kubeconfig files
  • cluster-info Display cluster info
  • api-versions Print the supported API versions on the server, in the form of "group/version".
  • version Print the client and server version information.
  • explain Documentation of resources.
  • convert Convert config files between different API versions
  • top Display Resource (CPU/Memory/Storage) usage

Author

Masashi Shibata

LICENSE

This software is licensed under the MIT License (See LICENSE).

kube-prompt's People

Contributors

c-bata avatar fiws avatar ghouscht avatar knqyf263 avatar kopwei avatar nathanjiangcs avatar prayashm avatar ultimateboy avatar wjkohnen avatar wzshiming 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kube-prompt's Issues

Configurable colors

Would be nice to have the colors configurable.
I'm using black on white terminal and the yellow prompt is hardly readable for me.

Fails if .kube/config has another name

I have 3 different cluster configs, all set in KUBECONFIG. All have different names than just config
kube-prompt fails when I try to get a certain pod or service

>>> get pods panic: stat /Users/tarekmehrez/.kube/config: no such file or directory

goroutine 36 [running]:
github.com/c-bata/kube-prompt/kube.NewClient(0x0)
	/Users/a14737/go/src/github.com/c-bata/kube-prompt/kube/client.go:29 +0x140
github.com/c-bata/kube-prompt/kube.getClient(0x0)
	/Users/a14737/go/src/github.com/c-bata/kube-prompt/kube/client.go:14 +0x2e
github.com/c-bata/kube-prompt/kube.fetchPods()
	/Users/a14737/go/src/github.com/c-bata/kube-prompt/kube/resource.go:177 +0x72
created by github.com/c-bata/kube-prompt/kube.getPodSuggestions
	/Users/a14737/go/src/github.com/c-bata/kube-prompt/kube/resource.go:183 +0x39

Is there a way that this might work by checking the config files set in the KUBECONFIG env var?
Thanks

Setting default namespace

I think this feature would be very useful when we're working in certain namespace. For example, we would execute kube-prompt --namespace staging to set default namespace to staging if not set explicitly in the prompt. So we don't need to type --namespace option for each commands.

Bonus:
Taking more generic approach, it would be better if kube-prompt CLI accept options from original kubectl command as defaults. For example, executing kube-prompt --namespace dev -o wide sets default namespace to dev and output format to wide for any compatible commands. (i.e. it behaves like currying/partial application in functional programming)

brew: Calling bottle :unneeded is disabled

We get the following error when installing kube-prompt with brew.

$ brew install c-bata/kube-prompt/kube-prompt
Error: c-bata/kube-prompt/kube-prompt: Calling bottle :unneeded is disabled! There is no replacement.
Please report this issue to the c-bata/kube-prompt tap (not Homebrew/brew or Homebrew/core):
  /opt/homebrew/Library/Taps/c-bata/homebrew-kube-prompt/kube-prompt.rb:5

Looking for co-maintainers

In response to #21 and all kube-prompt's users.

After publishing kube-prompt, I'm pleased that many users more than I expected use this. But I don't have enough time and mental energy to reply issues, check PRs and update version of kubernetes/client-go. So I'm looking for one or more co-maintainers that can help me.

If you are interested, please reply to this issue.
Thanks.

odd view when type `--`

Im going to type get pod --namespace XXX
but when type get pod --, it show odd view, seems miss a new line:
image

environment:
kube-prompt v1.0.4 (rev-61ddcfd)
mac item2

resources are not prompted

First of all, thanks for the project, this tool is awesome.
I'm using it but from the gifs you provided I understand that it also supports prompting names of actual resources that are available in my cluster. For example if I write "get pods a" it should prompt me all pods that start with "a". Unfortunately it doesn't work for me and I have no idea how to troubleshoot that. Any ideas?

Accept custom OptionPrefix as CLI argument

I would like to be able to run kube-prompt with something like:

$ kube-prompt --prefix "foo>"

and then be given a prompt with prompt.OptionPrefix set to foo>.

This could be useful when running kube-prompt in different contexts to know which one you are in.

Fails if there's no config in ~/.kube

I have 3 different contexts, all set in KUBECONFIG.
kube-prompt fails when I try to get a certain pod or service

>>> get pods panic: stat /Users/tarekmehrez/.kube/config: no such file or directory

goroutine 36 [running]:
github.com/c-bata/kube-prompt/kube.NewClient(0x0)
	/Users/a14737/go/src/github.com/c-bata/kube-prompt/kube/client.go:29 +0x140
github.com/c-bata/kube-prompt/kube.getClient(0x0)
	/Users/a14737/go/src/github.com/c-bata/kube-prompt/kube/client.go:14 +0x2e
github.com/c-bata/kube-prompt/kube.fetchPods()
	/Users/a14737/go/src/github.com/c-bata/kube-prompt/kube/resource.go:177 +0x72
created by github.com/c-bata/kube-prompt/kube.getPodSuggestions
	/Users/a14737/go/src/github.com/c-bata/kube-prompt/kube/resource.go:183 +0x39

Is there a way that this might work just by checking my current context?

can't navigate through the combobox items

I cannot navigate through the items of a completion combobox. I was expecting something similar to the interactive mode of az/gcloud/aws-shell.
Anyway that's a really cool tool you have, thanks for sharing !

Windows binaries

Hi,
Your project seems amazing. Could you publish windows 64bits binaries?
Thx,

Extending the GNU readline support

Hey @c-bata ๐Ÿ‘‹ Thanks so much for kube-prompt.
I use it every day and love it ๐Ÿ‘Œ

It'd be nice if it supported the 'Alt' key set of shortcuts from GNU readline.
As most others are already supported (Ctrl+A, Ctrl+E, Ctrl+K, etc.), I figured this would be a reasonable request.

I'd love to contribute myself and submit an MR for this. In fact this is something I wanted to include in my contributions toakavel/up a while back, but couldn't quite work out how to do it.

Perhaps if you can spare a moment, you might be able to hint/point me in the right direction? ๐Ÿ™
I'll have a look over the code and see where I get to, but I wanted to ask first if this is a contribution you'd be happy with?

Is there a reason kube-prompt needs to fetch all namespaces?

I noticed that when I try to start kube-prompt and my current context has a user that is not allowed to list all namespaces that it prompts me the fallowing error:

error namespaces is forbidden: User "system:serviceaccount:<name>:<another-name>" cannot list namespaces at the cluster scope

However, kube-prompt works just fine when I switch to a user without namespace list right from a user with those rights.

Allow specifying context and namespace as ENV vars or CLI params

I have an admin host that has a kubeconfig.yml file with many clusters and contexts configured. The YAML file is shared between many users, so it's read only.

It would be great if I could set an ENV var or pass a command line prompt which would set the default context or namespace of all the commands I run in kube prompt.

Something like:

kube-prompt --context=test-cluster --namespace=default

or

export CONTEXT=test-cluster NAMESPACE=default
kube-prompt

When I use kubectl in my day-to-day, I usually create aliases like:

alias kc="kubectl --context=test-cluster --namespace=default"
kc get pods

So this feature request would allow me to do the equivalent with kube-prompt.

Btw, great utility! Thanks for creating it!

`panic: runtime error: index out of range` on leading -n

$ kube-prompt 
kube-prompt v1.0.6 (rev-298f692)
Please use `exit` or `Ctrl-D` to exit this program.
>>> get pod -n automation-hub
NAME                                                       READY   STATUS    RESTARTS   AGE
api-59bf57744b-n9kv4                                       1/1     Running   0          5d1h
...
>>> -nBye!
panic: runtime error: index out of range

goroutine 1 [running]:
github.com/c-bata/kube-prompt/kube.(*Completer).argumentsCompleter(0xc0002d15e0, 0xc00038e5b2, 0xb, 0xc00032b400, 0x0, 0x2, 0x0, 0x0, 0x0)
	/Users/a14737/go/src/github.com/c-bata/kube-prompt/kube/arguments.go:98 +0x8955
github.com/c-bata/kube-prompt/kube.(*Completer).Complete(0xc0002d15e0, 0xc0005b4c6c, 0x3, 0x3, 0x0, 0xffffffffffffffff, 0xc0004bbcf8)
	/Users/a14737/go/src/github.com/c-bata/kube-prompt/kube/completer.go:83 +0x38c
github.com/c-bata/kube-prompt/kube.(*Completer).Complete-fm(0xc0005b4c6c, 0x3, 0x3, 0x1c12280, 0xc000398401, 0xc00032b380)
	/Users/a14737/go/src/github.com/c-bata/kube-prompt/main.go:35 +0x48
github.com/c-bata/kube-prompt/vendor/github.com/c-bata/go-prompt.(*CompletionManager).Update(0xc00043c820, 0xc0005b4c6c, 0x3, 0x3)
	/Users/a14737/go/src/github.com/c-bata/kube-prompt/vendor/github.com/c-bata/go-prompt/completion.go:69 +0x48
github.com/c-bata/kube-prompt/vendor/github.com/c-bata/go-prompt.(*Prompt).Run(0xc000395400)
	/Users/a14737/go/src/github.com/c-bata/kube-prompt/vendor/github.com/c-bata/go-prompt/prompt.go:85 +0x625
main.main()
	/Users/a14737/go/src/github.com/c-bata/kube-prompt/main.go:41 +0x37a

Register at a homebrew official repository

kube-prompt is gradually becoming a little bit famous. So perhaps it is the worth to register at a homebrew official repository.
It is a little bit comfortable because we don't need brew tap.

Missing client-go oidc auth helper (and others)

Currently kube-prompt only imports the gcp auth helper

import (
"k8s.io/client-go/kubernetes"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp" // register gcp auth helper
"k8s.io/client-go/tools/clientcmd"
)

Please could you also import the oidc helper with a blank identifier so it is included in the release builds?

 _ "k8s.io/client-go/plugin/pkg/client/auth/oidc"

Although I wonder if you might want to just import support for all of the available auth plugins rather than adding them one-by-one when people request them?

No Auth Provider found for name "azure"

seems like kube-prompt can't log to Azure Kubernetes Service (aka AKS). any idea whether this is only configuration to do on my part or is this requires an update (from other k8s related projects, seems it's on the client end to add some package

CVE issues

A trivy scan of the repo indicates that there a few CVE issues with dependencies (likely k8s libraries). Please consider updating the libraries to address the (>= HIGH) vulnerabilities.

+-----------------------------+------------------+----------+-----------------------------------+------------------------------------+---------------------------------------+
|           LIBRARY           | VULNERABILITY ID | SEVERITY |         INSTALLED VERSION         |           FIXED VERSION            |                 TITLE                 |
+-----------------------------+------------------+----------+-----------------------------------+------------------------------------+---------------------------------------+
| github.com/dgrijalva/jwt-go | CVE-2020-26160   | HIGH     | 3.2.0+incompatible                | v4.0.0-preview1                    | jwt-go: access restriction            |
|                             |                  |          |                                   |                                    | bypass vulnerability                  |
|                             |                  |          |                                   |                                    | -->avd.aquasec.com/nvd/cve-2020-26160 |
+-----------------------------+------------------+          +-----------------------------------+------------------------------------+---------------------------------------+
| golang.org/x/crypto         | CVE-2020-29652   |          | 0.0.0-20190820162420-60c769a6c586 | v0.0.0-20201216223049-8b5274cf687f | golang: crypto/ssh: crafted           |
|                             |                  |          |                                   |                                    | authentication request can            |
|                             |                  |          |                                   |                                    | lead to nil pointer dereference       |
|                             |                  |          |                                   |                                    | -->avd.aquasec.com/nvd/cve-2020-29652 |
+                             +------------------+          +                                   +------------------------------------+---------------------------------------+
|                             | CVE-2020-9283    |          |                                   | v0.0.0-20200220183623-bac4c82f6975 | golang.org/x/crypto: Processing       |
|                             |                  |          |                                   |                                    | of crafted ssh-ed25519                |
|                             |                  |          |                                   |                                    | public keys allows for panic          |
|                             |                  |          |                                   |                                    | -->avd.aquasec.com/nvd/cve-2020-9283  |
+-----------------------------+------------------+----------+-----------------------------------+------------------------------------+---------------------------------------+

container name completion

kube-prompt doesn't support completion for container name.

kubectl logs <pod name> -c <container name>
                                  โ†‘ this one

Add ARM arch support in order to run on RPi 4

On newly released RPi4, ARM64 support is out of official roadmap. Ubuntu ARM64 for RPi4 is not release yet. Thus we hope to build a binary for ARM32 which could be run on Raspbian system which is officially supported by Raspberry Pi (2, 3 and 4)

Set default namespace in a session

Today you have to set the namespace when you start the session or specify it each command. It would be create to be able to switch the namespace or even the context while in a session.

Example proposal

!namespace "namespace autocomplete"
!ns "namespace autocomplete"

panic: invalid configuration: no configuration has been provided

Hello, I trying kube-prompt with microk8s on Ubuntu 18.04.

I installed microk8s using the following commands:

sudo snap install microk8s --classic
sudo snap alias microk8s.kubectl kubectl

kube-prompt seems to work well, until you invoke a 'describe no' command

>>> get nodes
NAME       STATUS   ROLES    AGE     VERSION
hos54985   Ready    <none>   6h22m   v1.14.2
>>> describe no panic: invalid configuration: no configuration has been provided

goroutine 9 [running]:
github.com/c-bata/kube-prompt/kube.NewClient(0x114f6ff)
	/build/go/src/github.com/c-bata/kube-prompt/kube/client.go:28 +0x1ad
github.com/c-bata/kube-prompt/kube.getClient(...)
	/build/go/src/github.com/c-bata/kube-prompt/kube/client.go:15
github.com/c-bata/kube-prompt/kube.fetchNodeList()
	/build/go/src/github.com/c-bata/kube-prompt/kube/resource.go:464 +0x114
created by github.com/c-bata/kube-prompt/kube.getNodeSuggestions
	/build/go/src/github.com/c-bata/kube-prompt/kube/resource.go:470 +0x39

Do you have any idea for how to fix this issue?
Thanks

[feature] allow run shell command directly in prompt

Thanks to develop this tool which saved me a lot of typing time.

I ask for the feature which I needn't jump out of prompt to run other shell commands, such as ls, find, curl, and even kubectx (k8s cluster switch) and kubens (k8s namespace switch)

For example, I prefer a feature, if I add ! in front of command, it will run shell command, not kubectl command.

>>> ! ls 

Please vote this idea, if you like

When using a context with a namespace that is not `default`, pod completion is for default namespace

First off, thanks for writing this tool, it looks like it should be pretty helpful. Excited to start using it more.

This is for version 1.0.1:

As you can see below my context is registered to use the seu namespace by default, but the completions are from the default namespace. But then when the actual command is run it uses the proper namespace, and therefore can't find my auto completed pod.

>>> get pods --all-namespaces
NAMESPACE     NAME                                                                READY     STATUS             RESTARTS   AGE
...
default       canopy-2965694291-f5f6c                                             1/1       Running            0          1d
default       canopy-2965694291-kjbqq                                             1/1       Running            0          1d
...
seu           hello-world-v13-1574404032-4hzxd                                    1/1       Running            0          62d
...
>>> describe pod 
                  ...
                  canopy-2965694291-f5f6c        Running 
                  canopy-2965694291-kjbqq        Running 

>>> describe pod canopy-2965694291-f5f6c
Error from server (NotFound): pods "canopy-2965694291-f5f6c" not found
Got error: exit status 1

>>> describe pod hello-world-v13-1574404032-4hzx
Name:		hello-world-v13-1574404032-4hzxd
Namespace:	seu
...

Display Context

Hello, thanks for this. Is there a way you could support displaying which context is current on the cli please?

Good News! gcloud will support interactive shell mode.

To all kube-prompt's users

In public alpha version of gcloud, interactive shell mode is added. This feature provides interactive completion of kubectl's subcommands, not to mention a gcloud's subcommands (See https://cloudplatform.googleblog.com/2018/03/introducing-GCPs-new-interactive-CLI.html
for more details)

Some features still lack but it will be improved in the future (ex: kube-prompt and kube-shell provides feature to complete kubernetes resources such as pods, deployments and so on). It's great news, but it means the worth of kube-prompt will be disappear anymore. Therefore I will not actively develop kube-prompt.

Thanks.

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.