我正在设置一个 kubernet 集群来部署我们的容器应用程序。应用程序实际上需要所有标签,但标签超过 63 个字符,我得到一个 error .这使我依赖于注释。
服务的注释如下所示:com.example.development.london/component.proxy-config.secure-routes.backend.proxy-path
。 /
仅用于绕过 RFC 域错误。
在 Golang 应用程序中,请求命名空间的所有服务。实际上基于标签。为此,到目前为止我使用了以下代码。
func (kc *KubernetesCollector) generateRoutes(errorChannel chan<- error) {
log.Println("INFO: Try to generate routes")
services, err := kc.iface.Services(kc.namespace).List(metav1.ListOptions{
LabelSelector: fmt.Sprintf("%s==true", ConvertLabelToKubernetesAnnotation(ProxyConfDiscoverableLabel)),
})
...
func ConvertLabelToKubernetesAnnotation(label string) string {
return strings.Replace(label, "com.example.development.london.", "com.example.development.london/", -1)
}
但是不可能使用注解返回服务。有谁知道另一种方法我可以如何使用 Go 获取适用于注释的所有服务?
最佳答案
如 Kubernetes documentation 中所述,注释用于非识别信息,因此您自然不应该使用它们来查找对象。
如果这是一个选项,您可以通过以下方式将前缀(最大长度为 253 个字符)附加到您的标签:<label prefix>/<label name>
.可以从上面提供的链接找到更多信息。
关于go - kubernetes API中是否有通过注解获取所有服务的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56108743/