kubernetes: kubectl config current-context is slow
What would you like to be added:
If possible, it would be great to have kubectl config current-context
performance be improved.
Why is this needed: I sometimes do commands thinking my context is one thing, but end up modifying a cluster I didn’t intend to. To help avoid this, I changed my shell prompt to print out my kubectl context. But since the command is slow, every command I run in my shell causes a few hundred ms delay before I see the prompt again.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 16 (5 by maintainers)
Hopefully this helps anyone still running into this: I managed to speed it up by deleting old entries (clusters, contexts, and users) in
~/.kube/config
. I had a bunch of configs for old AWS clusters I was no longer using, as well as a localkind
cluster. I removed everything except GKE clusters which are currently up and running, and now mykubectl
commands are very fast again.Maybe the CLI was trying to communicate with these defunct clusters and failing after some timeout? If that is the case, seems like a bug. It seemed to be happening on every command – even my
kubectl completion bash
command was greatly slowed down, causing my shell startup to take 5 seconds or so.Side note, if you want an alternative to
kubectl config current-context
that is fast enough to be used for a shell prompt, try this:This command runs in about 2ms, vs
kubectl config get-context
which takes 32ms on my setup.I’ve just somehow gotten the same issue(?). Not sure what changed actually, haven’t added any new clusters or changed config.
A few runs of:
I’m also using
oh-my-zsh
kubectl
plugin which leverages the command to show current context and thats what got me digging as shell got so much slower than usualEDIT:
figured out my local issue. When using the
gcloud-sdk
providedkubectl
it is indeed slow. When using thedocker-engine
provided its back to normal: