从集群获取资源的时间太长

huangapple go评论83阅读模式
英文:

k8s get resources from cluster take too much time

问题

我需要根据标签获取所有资源,我使用了以下代码可以工作,但是获取响应的时间太长(约20秒),即使我将其限制在一个命名空间(vrf)中,你有什么想法,我在这里做错了什么?

resource.NewBuilder(flags).
   Unstructured().
   ResourceTypes(res...).
   NamespaceParam("vrf").AllNamespaces(false).
   LabelSelectorParam("a=b").SelectAllParam(selector == "").
   Flatten().
   Latest().Do().Object()

我已经使用了labelns,不确定在这种情况下还应该做什么。

我已经检查了集群连接,似乎一切正常,运行常规的kubectl命令得到的响应非常快,只有这个查询花费了很长时间。

英文:

I need to get all resources based on label, I used the following code which works, However, it takes too much time ( ~20sec) to get the response, even which I restrict it to only one namespace (vrf), any idea what im doing wrong here?

resource.NewBuilder(flags).
   Unstructured().
   ResourceTypes(res...).
   NamespaceParam("vrf").AllNamespaces(false).
   LabelSelectorParam("a=b").SelectAllParam(selector == "").
   Flatten().
   Latest().Do().Object()

https://pkg.go.dev/k8s.io/cli-runtime@v0.26.1/pkg/resource#Builder

As I already using label and ns, not sure what should else I do in this case.

Ive checked the cluster connection and it seems that everything is ok, running regular kubectl are getting very fast response, just this query took much time.

答案1

得分: 1

搜索可能很耗时,因为查询需要搜索的资源非常庞大。你是否考虑过这种可能性,并进一步通过添加一个标签或筛选器来减小搜索范围。

同时,在执行操作时,请检查你的Kubernetes API服务器的性能并进行优化。

英文:

The search may be heavy due to the sheer size of the resources the query has to search into. Have you looked into this possibility and further reduce the size using one more label or filter on top of current.

Also check the performance of you Kubernetes api server when the operation is being performed and optimize it.

huangapple
  • 本文由 发表于 2023年2月5日 21:30:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/75352630.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定