使用 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

    justopen2年前 (2017-06-17)回复