Giter Site home page Giter Site logo

kubectl-match-name's Introduction

kubectl-match-name

Access pods quickly without using the clipboard or listing all pods first. Here are some typical use cases:

$ kubectl logs `kubectl match-name proxy` -f
I0207 12:51:25.322909       1 server.go:444] Version: v1.10.0
...
$ kubectl match-name proxy
kube-proxy-cvtm5
$ kubectl match-name -k svc .
default-http-backend
$ kubectl match-name minikube
etcd-minikube kube-addon-manager-minikube kube-apiserver-minikube kube-controller-manager-minikube kube-scheduler-minikube

Let's take a closer look at the first example. What have we gained? This line replaces two common approaches. In many cases we would use the clipboard or type in the hash component of the name:

$ kubectl get po | grep proxy
kube-proxy-cf2df                            1/1     Running   0          5h
kube-proxy-8dj6v                            1/1     Running   0          5h
kube-proxy-s6wvq                            1/1     Running   0          5h
$ kubectl logs kube-proxy-cf2df -f

What about a one-liner? It's straightforward but hardly concise:

$ kubectl logs `kubectl get po --no-headers | grep proxy | cut -d' ' -f1 | head -n1` -f

Why not just a shell script? Mainly because it probably will not work as intended on Windows. It is hard to overestimate the number of Kubernetes users using kubectl via Git Bash or PowerShell.

Note that although the binary itself is called kubectl-match_name, it is invoked by the command kubectl match-name.

Usage

$ kubectl match-name -h
Usage: kubectl-match_name [-kubeconfig=PATH] [-a] [-k KIND] [-n NAMESPACE] REGEX
  -A    match in all namespaces
  -a    return all matching objects
  -c    count matching objects (implies -a)
  -k string
        match objects of kind (default "pod")
  -kubeconfig string
        absolute path to the kubeconfig file
  -n string
        namespace

The search expression is interpreted by the Golang regexp package (sadly not PCRE).

Run

To try the plugin on your computer, download one of the release binaries above (Linux, Mac, Windows).

Build

$ make
$ sudo make install

kubectl-match-name's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

kubectl-match-name's Issues

Returned name contains a leading space

$ echo "pod/$(kubectl match-name -n kube-system coredns)"
pod/ coredns-7987f4d48b-nczg7

This causes problems e.g. when concatenating as you can see above.

Versions:

$ kubectl version                     
Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.4", GitCommit:"b695d79d4f967c403a96986f1750a35eb75e75f1", GitTreeState:"clean", BuildDate:"2021-11-17T15:48:33Z", GoVersion:"go1.16.10", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.9", GitCommit:"7a576bc3935a6b555e33346fd73ad77c925e9e4a", GitTreeState:"clean", BuildDate:"2021-07-15T20:56:38Z", GoVersion:"go1.15.14", Compiler:"gc", Platform:"linux/amd64"}
WARNING: version difference between client (1.22) and server (1.20) exceeds the supported minor version skew of +/-1

$ unbuffer kubectl krew list  | grep match-name
match-name   v0.1.3

[krew] Distribute with license

👋 Hello, maintainer of the kubectl plugin manager krew here.

Thank you for your commitment to open source by making this plugin available via krew!

Krew wants to give credit where credit is due by installing the proper license file for the plugins it distributes. However, your plugin was found to not contain any license file. We wanted to remind you that if you're using a license such as Apache 2.0, you should be bundling your LICENSE file with your plugin’s distributions.

What do you have to do?

  • Please ensure your GitHub repository has a license file.
  • Make sure your archive file (.tar.gz or .zip) contains the license file.
  • Please submit a pull-request to krew-index and update the files: section to copy the file to the installation directory. Have a look at this PR for an example: https://github.com/kubernetes-sigs/krew-index/pull/314/files

If you need further assistance, don't hesitate to ask for help.

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.