英文:
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()
我已经使用了label
和ns
,不确定在这种情况下还应该做什么。
我已经检查了集群连接,似乎一切正常,运行常规的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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论