kubectl: kubectl completion, config current-context and version commands are too slow
What happened?
Commands kubectl completion zsh, kubectl config current-context, kubectl version and many others are too slow because they are trying to connect to the server.
This is very annoying behaviour which causes slow opening of new terminal (~0.5s with VPN and ~5s without VPN, when connection isn’t possible).
I don’t see any reason for those commands to connect to any server, they should just return output locally.
What did you expect to happen?
All the commands run ~0.05s, like they do without any network connection:
$ time kubectl completion zsh > /dev/null
kubectl completion zsh > /dev/null 0.05s user 0.01s system 126% cpu 0.044 total
How can we reproduce it (as minimally and precisely as possible)?
Without VPN:
$ time kubectl version
WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short. Use --output=yaml|json to get the full version.
Client Version: version.Info{Major:"1", Minor:"27+", GitVersion:"v1.27.9-dispatcher", GitCommit:"8b508a33aafcd3ba51641b6b2ef203adbdd9de1e", GitTreeState:"clean", BuildDate:"2023-12-21T23:22:51Z", GoVersion:"go1.20.12", Compiler:"gc", Platform:"linux/amd64"}
Kustomize Version: v5.0.1
Unable to connect to the server: dial tcp 10.xxx.xxx.xxx:443: i/o timeout
kubectl version 0.05s user 0.03s system 0% cpu 35.058 total
$ time kubectl completion zsh > /dev/null
kubectl completion zsh > /dev/null 0.05s user 0.05s system 1% cpu 5.075 total
$ time kubectl config current-context
XXXXXXXXX
kubectl config current-context 0.07s user 0.03s system 1% cpu 5.078 total
With VPN connected (still annoyingly slow):
$ time kubectl version
WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short. Use --output=yaml|json to get the full version.
Client Version: version.Info{Major:"1", Minor:"27+", GitVersion:"v1.27.9-dispatcher", GitCommit:"8b508a33aafcd3ba51641b6b2ef203adbdd9de1e", GitTreeState:"clean", BuildDate:"2023-12-21T23:22:51Z", GoVersion:"go1.20.12", Compiler:"gc", Platform:"linux/amd64"}
Kustomize Version: v5.0.1
Server Version: version.Info{Major:"1", Minor:"27", GitVersion:"v1.27.8-gke.1067000", GitCommit:"3936242da351c64ea89912f00faa0b28fb7eab76", GitTreeState:"clean", BuildDate:"2023-12-06T20:41:34Z", GoVersion:"go1.20.11 X:boringcrypto", Compiler:"gc", Platform:"linux/amd64"}
kubectl version 0.07s user 0.03s system 9% cpu 1.087 total
$ time kubectl completion zsh > /dev/null
kubectl completion zsh > /dev/null 0.04s user 0.03s system 16% cpu 0.414 total
$ time kubectl config current-context
XXXXXXXXX
kubectl config current-context 0.06s user 0.03s system 20% cpu 0.444 total
Anything else we need to know?
There was previous issue https://github.com/kubernetes/kubernetes/issues/82883, which was closed without resolution, also please do not mark this as feature: it’s a bug because kubecli can and should run the commands for ~0.05s but run for 0.5s or even 5s.
Kubernetes version
$ kubectl version
WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short. Use --output=yaml|json to get the full version.
Client Version: version.Info{Major:"1", Minor:"27+", GitVersion:"v1.27.9-dispatcher", GitCommit:"8b508a33aafcd3ba51641b6b2ef203adbdd9de1e", GitTreeState:"clean", BuildDate:"2023-12-21T23:22:51Z", GoVersion:"go1.20.12", Compiler:"gc", Platform:"linux/amd64"}
Kustomize Version: v5.0.1
Server Version: version.Info{Major:"1", Minor:"27", GitVersion:"v1.27.8-gke.1067000", GitCommit:"3936242da351c64ea89912f00faa0b28fb7eab76", GitTreeState:"clean", BuildDate:"2023-12-06T20:41:34Z", GoVersion:"go1.20.11 X:boringcrypto", Compiler:"gc", Platform:"linux/amd64"}
Cloud provider
OS version
# On Linux:
$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux trixie/sid"
NAME="Debian GNU/Linux"
VERSION_CODENAME=trixie
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
$ uname -a
Linux xxxxx 6.6.9-amd64 kubernetes/kubernetes#1 SMP PREEMPT_DYNAMIC Debian 6.6.9-1 (2024-01-01) x86_64 GNU/Linux
Install tools
$ apt policy kubectl
kubectl:
Installed: 1:460.0.0-0
Candidate: 1:460.0.0-0
Version table:
*** 1:460.0.0-0 500
500 https://packages.cloud.google.com/apt cloud-sdk/main amd64 Packages
100 /var/lib/dpkg/status
Container runtime (CRI) and version (if applicable)
Related plugins (CNI, CSI, …) and versions (if applicable)
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 6
- Comments: 29 (10 by maintainers)
If
kubectl completionorkubectl version --clientor any other command that has a--localflag whose are designed not to send request to api server sends a request to api server when kubeconfig has a credentials exec plugin, I think that is a bug.We have found in the past that the Google Cloud provided kubectl binary is not in fact simply kubectl as built from this organizations build pipeline, so one thing I want to ensure is that everyone reporting the issue here is not using that version, and if they are then I would recommend that they open a support case with Google Cloud.
It does look like there are users with the kubernetes officially provided kubectl, which we will continue to investigate here.
I’ve tested it with
kubectlbuilt from https://github.com/kubernetes/kubernetes at 2d4100335e4c4ccc28f96fac78153f378212da4c and I wasn’t able to reproduce the problem.Also I wasn’t able to find git commit 8b508a33aafcd3ba51641b6b2ef203adbdd9de1e in the repo from kubectl version installed from https://packages.cloud.google.com/apt, so maybe there are some google’s patches added.
I don’t think that
kubectl completionhas any relation with sending any requests to API server.