当前位置: 首页 > 工具软件 > Go Getopt > 使用案例 >

client-go删除pods和server

公西俊民
2023-12-01
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"
	name, serviceName := "nginx", "nginx-svc"

	fmt.Println("已删除:", name)
	clientset.AppsV1().Deployments(namespace).Delete(context.TODO(), name, metav1.DeleteOptions{})

	clientset.CoreV1().Services(namespace).Delete(context.TODO(), serviceName, metav1.DeleteOptions{})
}

 类似资料: