client-go获取Deployments副本
package mainimport ("context""fmt"metav1 "k8s.io/apimachinery/pkg/apis/meta/v1""k8s.io/client-go/kubernetes""k8s.io/client-go/tools/clientcmd"//"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured")func
·
package main
import (
"context"
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
//"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)
func main() {
configPath := "C:\\Users\\admin\\Desktop\\api-six\\k8s-config-admin"
config, _ := clientcmd.BuildConfigFromFlags("", configPath)
clientset, _ := kubernetes.NewForConfig(config)
namespace := "devops"
fmt.Println("命名空间:", namespace)
list, err := clientset.AppsV1().Deployments(namespace).List(context.TODO(), metav1.ListOptions{})
if err != nil {
panic(err)
}
for _, d := range list.Items {
fmt.Printf(" * %s (%d replicas)\n", d.Name, *d.Spec.Replicas)
}
}
更多推荐
已为社区贡献82条内容
所有评论(0)