导语:删除deloyment
deleteResource.go
package main
import (
"context"
"fmt"
"log"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
)
func main() {
configPath := "./config"
config, err := clientcmd.BuildConfigFromFlags("", configPath)
if err != nil {
log.Fatal(err)
}
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
panic(err)
}
namespace := "default"
name, serviceName := "nginx", "nginx-service"
// 获取名为nginx的deployment信息
deploymentList, err := clientset.AppsV1().Deployments(namespace).Get(context.TODO(), name, metav1.GetOptions{})
fmt.Println(err, deploymentList)
// 删除deployment
clientset.AppsV1().Deployments(namespace).Delete(context.TODO(), name, metav1.DeleteOptions{})
// 删除svc
clientset.CoreV1().Services(namespace).Delete(context.TODO(), serviceName, metav1.DeleteOptions{})
// 删除ingress
// clientset.ExtensionsV1beta1().Ingresses()
}
go run deleteResource.go
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)