使用 client-go 控制原生及拓展的 Kubernetes API | 视频

使用 client-go 控制原生及拓展的 Kubernetes API

K8S中文社区微信公众号

评论 1

登录后评论

立即登录  

  1. #1

    I have more then 5 kubernetes clusters.
    Below is my code,

    func ListAllNodes(configPath string) {
    config, err := clientcmd.BuildConfigFromFlags(, configPath)
    clientSet, err := kubernetes.NewForConfig(config)
    nodes,err := clientSet.CoreV1().Nodes().List(metav1.ListOptions{})
    fmt.Println(err)
    fmt.Println( len(nodes.Items))
    }
    ListAllNodes(/home/cluster1/config)
    ListAllNodes(/home/cluster2/config)
    ListAllNodes(/home/cluster3/config)
    ListAllNodes(/home/cluster4/config)
    ListAllNodes(/home/cluster5/config)

    Here is output:

    2
    5
    Forbidden: /api/v1/nodes (get nodes) UnexpectedServerResponse Forbidden
    Forbidden: /api/v1/nodes (get nodes) UnexpectedServerResponse Forbidden
    Forbidden: /api/v1/nodes (get nodes) UnexpectedServerResponse Forbidden

    If I change the cluster order, still work for first two clusters. The rest cluster doesn’t work.

    func ListAllNodes(configPath string) {
    config, err := clientcmd.BuildConfigFromFlags(, configPath)
    clientSet, err := kubernetes.NewForConfig(config)
    nodes,err := clientSet.CoreV1().Nodes().List(metav1.ListOptions{})
    fmt.Println(err)
    fmt.Println( len(nodes.Items))
    }
    ListAllNodes(/home/cluster5/config)
    ListAllNodes(/home/cluster4/config)
    ListAllNodes(/home/cluster1/config)
    ListAllNodes(/home/cluster2/config)
    ListAllNodes(/home/cluster3/config)

    Here is output:

    6
    2
    Forbidden: /api/v1/nodes (get nodes) UnexpectedServerResponse Forbidden
    Forbidden: /api/v1/nodes (get nodes) UnexpectedServerResponse Forbidden
    Forbidden: /api/v1/nodes (get nodes) UnexpectedServerResponse Forbidden

    justopen7年前 (2017-06-17)