我想使用client-go来获取Kubernetes集群中的资源。由于大量数据,当我得到configmap连接时,它已关闭。
stream error when reading response body, may be caused by closed connection. Please retry. Original error: stream error: stream ID 695; INTERNAL_ERROR
configmaps:
$ kubectl -n kube-system get cm |wc -l
35937
代码:
cms, err := client.CoreV1().ConfigMaps(kube-system).List(context.TODO(), v1.ListOptions{})
我尝试使用Limit参数,我可以获取一些数据,但我不知道如何获取所有数据。
cms, err := client.CoreV1().ConfigMaps(kube-system).List(context.TODO(), v1.ListOptions{Limit: 1000 })
我是新手。任何关于如何实现它的指针将不胜感激。
最佳答案
v1.ListOptions的文档描述了它的工作方式:
limit is a maximum number of responses to return for a list call. If more items exist, the server will set the
continue
field on the list metadata to a value that can be used with the same initial query to retrieve the next set of results.
这意味着您应该检查响应,保存
continue
字段的值(以及实际结果),然后重新发出相同的命令,但continue
设置为刚刚看到的值。重复直到返回的continue
字段为空(或发生错误)。有关处理大型结果的分块的详细信息,请参见API concepts页面。
关于go - golang获取kubernetes资源(30000+ configmaps)失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61674050/