onatm / kubectl-allctx Goto Github PK
View Code? Open in Web Editor NEWRun 'kubectl' commands on contexts in your kubeconfig
License: MIT License
Run 'kubectl' commands on contexts in your kubeconfig
License: MIT License
I am having serious trouble understanding how this plugin works without reading its source code.
$ k allctx --like c0 get pods -n compute-system
Error from server (NotFound): pods "compute-system" not found
$ k allctx --like c0 -n compute-system get pods
Error: flags cannot be placed before plugin name: --context=...
Error: flags cannot be placed before plugin name: --context=...
Error: flags cannot be placed before plugin name: --context=...
Error: flags cannot be placed before plugin name: --context=...
Error: flags cannot be placed before plugin name: --context=...
Error: flags cannot be placed before plugin name: --context=...
Hi
I manage krew-release-bot, a bot to automatically do version bump PR with krew-index repo once new release is made.
request you to kindly consider including the bot in your release process. FYI, it does not require any credentials as such to work.
a sample PR: kubernetes-sigs/krew-index#1271
Thanks
Rajat Jindal
Assuming some day you are planning to rework this tool, providing some ideas.
I think rewriting this tool in Go would be immensely useful. I'm, for example, running this tool on massively large clusters and many commands take >30s to return sometimes, and I run grep on these. Parallelization would greatly benefit.
I think some form of kubectl allctx [OPTIONS] CONTEXT_SPEC[...CONTEXT_SPEC] -- [KUBECTL_ARGS...]
should be useful.
The --
separation would disambiguate and future-proof allctx for future expansion with new args/subcmds and not them be confused with args to kubectl.
Hypothetical examples:
# all contexts:
kubectl allctx -- get nodes
# some contexts
kubectl allctx c1 c2 c3 -- get nodes
# pattern matching
kubectl allctx ~'.*-prod$' -- get nodes
I typically grep things for output, e.g. if I wanted to find unschedulable nodes across prod clusters I'd want to run something like kubectl allctx ~'.*-prod$' -- get nodes | grep SchedulingDisabled
. It's important in the grep output to be able to see which cluster the node belongs to.
So I will recommend prefixing all outputs with context name, e.g.:
$ kubectl allctx c1 c2 -- get nodes
c1 | NAME STATUS ROLES AGE VERSION
c1 | x-ayx-36-sr1.prod.x.com Ready <none> 68d v1.20.5
c1 | x-bpk-27-sr1.prod.x.com Ready <none> 63d v1.20.5
c2 | NAME STATUS ROLES AGE VERSION
c2 | x-ayx-22-sr1.prod.x.com Ready <none> 68d v1.20.5
c2 | x-bpk-11-sr1.prod.x.com Ready <none> 63d v1.20.5
This is probably good enough to begin with.
A rewrite in go can enable running all kubectl commands in parallel.
However, some users might want to see output lines from the same context next to each other. This can be the default behavior, and you'd buffer outputs and show them once they're fully ready. You can even show status of what contexts are currently being processed vs completed somewhere in stderr like:
Still running: 9 of 12 contexts completed.
Some users will want to see output as they arrive (prefixed by context as described above) as paging over long lists can take very long. For example, running kubectl allctx -- logs --label foo=bar --follow
is not something you can buffer as the logs
command will run indefinitely, and in that case, you can still output the lines as they arrive (prefixed by context name, described above). e.g.:
$ kubectl allctx -- logs --label foo=bar --follow
c1| message from pod1 in c1
c2| message from pod1 in c2
c1| message from pod5 in c1
c2| message from pod3 in c2
...
In this case, you need to be careful about preserving a lock over printing lines, otherwise the output lines may interleave and produce corrupted/undesired output.
You can expose these with options like --output-by-context
, or --output-live
like options to allctx
.
The above cmd won't work as kubectl logs only works for a single Pod. But there's a plugin "kubectl tail", which brings me to my next topic.
There are lots of good kubectl plugins out there, for example kubectl images
lists images in a cluster. I should be able to use it via allctx
, and allctx
would pass --context=...
to such plugins to make them work per-context.
However, not all plugins accept --context
at the end, so you might need to do what GNU xargs
command does.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.