Skip to content

Instantly share code, notes, and snippets.

@leoh0
Last active July 29, 2021 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leoh0/25f267b629b18ab584024a3c8c9082ab to your computer and use it in GitHub Desktop.
Save leoh0/25f267b629b18ab584024a3c8c9082ab to your computer and use it in GitHub Desktop.
kubectl을 느리게 사용하는 방법.
  • slow-kubectl.sh와 같이 했을시 걸리는 시간: 1m25.738s
$ time kubectl get all
I0401 17:58:21.966762   25969 request.go:621] Throttling request took 1.162451359s, request: GET:https://10.22.70.249:6443/apis/apiextensions.k8s.io/v1beta1?timeout=32s
I0401 17:58:32.166766   25969 request.go:621] Throttling request took 2.197797331s, request: GET:https://10.22.70.249:6443/apis/networking.k8s.io/v1beta1?timeout=32s
I0401 17:58:42.366787   25969 request.go:621] Throttling request took 2.798023909s, request: GET:https://10.22.70.249:6443/apis/networking.k8s.io/v1beta1?timeout=32s
I0401 17:58:52.566791   25969 request.go:621] Throttling request took 3.398025432s, request: GET:https://10.22.70.249:6443/apis/discovery.k8s.io/v1beta1?timeout=32s
I0401 17:59:02.766754   25969 request.go:621] Throttling request took 3.997812593s, request: GET:https://10.22.70.249:6443/apis/rbac.authorization.k8s.io/v1beta1?timeout=32s
I0401 17:59:12.767024   25969 request.go:621] Throttling request took 4.397012075s, request: GET:https://10.22.70.249:6443/apis/scheduling.k8s.io/v1beta1?timeout=32s
I0401 17:59:22.966411   25969 request.go:621] Throttling request took 4.99756897s, request: GET:https://10.22.70.249:6443/apis/rbac.authorization.k8s.io/v1?timeout=32s
I0401 17:59:33.166406   25969 request.go:621] Throttling request took 5.597814268s, request: GET:https://10.22.70.249:6443/apis/cluster.x-k8s.io/v1alpha3?timeout=32s
I0401 17:59:43.366378   25969 request.go:621] Throttling request took 6.197700919s, request: GET:https://10.22.70.249:6443/apis/controlplane.cluster.x-k8s.io/v1alpha3?timeout=32s
NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   45h

real	1m25.738s
user	0m0.696s
sys	0m0.118s
  • 그냥 /etc/kubernetes/admin.conf를 사용했을시 걸리는 시간 0m0.162s
$ time sudo KUBECONFIG=/etc/kubernetes/admin.conf kubectl get all
NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   45h

real	0m0.162s
user	0m0.172s
sys	  0m0.046s

문제

  • slow-kubectl.sh를 적용하면 이렇게 느려질까요?
# Test with non-root user
# Run in master node
if [ -f /etc/kubernetes/admin.conf ] && [ "$(id -u)" != 0 ] ; then
# backup directory
[ -d /home/$USER/.kube ] && sudo mv /home/$USER/.kube /home/$USER/.kube-backup-$(date +%s)
# 원본 코드 참고: https://github.com/metal3-io/metal3-dev-env/blob/f9d1fa8/vm-setup/roles/v1aX_integration_test/templates/controlplane_ubuntu.yaml#L63-L66
sudo mkdir -p /home/$USER/.kube
sudo cp /etc/kubernetes/admin.conf /home/$USER/.kube/config
sudo chown $USER:$USER /home/$USER/.kube/config
fi

아래로 정답을 확인하세요.

echo 'Cuq2jO2VnOusuOygnOuhnCAua3ViZSDrlJTroInthqDrpqzsl5Ag7LqQ7Ims66W8IOyDneyEsSDrqrvtlagKc3VkbyBjaG93biAtUiAkVVNFUjokVVNFUiAvaG9tZS8kVVNFUi8ua3ViZQoK' | base64 -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment