doushouj966020 2018-09-06 09:13
浏览 82
已采纳

使用Kubernetes的Go客户端列出Traefik入口控制器

We have a little internal tool listing our Kubernetes services using Go client for Kubernetes.

Now we have added Traefik to map our services to meaningful dns names using ingress controllers. We see that there is an ingress lister extension in Go client for Kubernetes that can be used to list ingress controllers. However, we could not make it work.

Are there any Go client code snippets listing ingress controllers?

  • 写回答

1条回答 默认 最新

  • dongluojiao6322 2018-09-06 11:52
    关注

    What have you tried so far? Posting examples helps. Try the following arbitrary example to get you started:

        // imports
        // metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
        // "k8s.io/client-go/kubernetes"
        // "k8s.io/client-go/tools/clientcmd"
    
        // create the clientset
        clientset, err := kubernetes.NewForConfig(config)
        if err != nil {
                panic(err.Error())
        }
        for {
                ingressList, err := clientset.ExtensionsV1beta1().Ingresses("").List(metav1.ListOptions{})
                if err != nil {
                        // handle err
                }
                ingressCtrls := ingressList.Items
                if len(ingressCtrls) > 0 {
                        for _, ingress := range ingressCtrls {
                                fmt.Printf("ingress %s exists in namespace %s
    ", ingress.Name, ingress.Namespace)
                        }
                } else {
                        fmt.Println("no ingress found")
                }
                time.Sleep(10 * time.Second)
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?