[golang]-client-go删除指定deloyment和svc

[golang]-client-go删除指定deloyment和svc,第1张

导语:删除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

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/994209.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存