douxian4888 2019-05-13 08:48 采纳率: 0%
浏览 133

kubernetes API中的功能可通过注释获取所有服务

I'm setting up a kubernet cluster to roll out our container applications. The applications actually need all labels, but the labels are longer than 63 characters and I get an error. This makes me dependent on annotations.

An annotation for a service looks like this: com.example.development.london/component.proxy-config.secure-routes.backend.proxy-path. The / only serves to bypass an RFC domain error.

In a Golang application all services of a namespace are requested. Actually based on the labels. For this I have used the following code so far.

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)
}

But there is no possibility to return the services using annotations. Does anyone know another way how I can get all services that apply to an annotation with Go?

  • 写回答

2条回答 默认 最新

  • dongya2030 2019-05-13 12:26
    关注

    As specified in the Kubernetes documentation, annotations are meant for non-identifying information, so naturally you shouldn't use them for finding objects.

    If that's an option, you can attach a prefix (max length of 253 characters) to your label in this manner: <label prefix>/<label name>. Additional information can be found from the link provided above.

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料