使用 client-go 控制原生及拓展的 Kubernetes API
立即登录 注册
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)
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
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