client-go 操作k8s常用API

deployment
// 列出 deploymentList
    deploymentList, err := clientset.AppsV1().Deployments("default").List(metav1.ListOptions{})
 
// 查询 deploymentGet
	deploymentGet, err := clientset.AppsV1().Deployments("default").Get("nginx-web-v2", metav1.GetOptions{})

// 创建 deploymentCreate
	deploymentCreate, err := clientset.AppsV1().Deployments("default").Create(deploymentName)

// 更新 deploymentUpdate
	deploymentUpdate, err := clientset.AppsV1().Deployments("default").Update(deploymentName)

// 删除deployment
    err = clientset.AppsV1().Deployments("default").Delete("deploymentName", &metav1.DeleteOptions{})
pod
不写命令空间  即列出所有pod
//列出pod
podList, err := clientset.CoreV1().Pods("default").List(&meta_v1.ListOptions{})

//查询pod
pod, err := clientset.CoreV1().Pods("default").Get(<podName>, meta_v1.GetOptions{})

//创建pod
pod, err := clientset.CoreV1().Pods("default").Create(web)

//更新pod
pod, err := clientset.CoreV1().Pods("default").Update(web)

//删除pod
err := clientset.CoreV1().Pods("default").Delete(<podName>, &meta_v1.DeleteOptions{})
statefulset
// 列出 statefulList
	statefulList, err := clientset.AppsV1().StatefulSets("default").List(metav1.ListOptions{})
 
// 查询 statefulGet
	statefulGet, err := clientset.AppsV1().StatefulSets("default").Get("web", metav1.GetOptions{})
// 创建 statefulCreate
	statefulCreate, err := clientset.AppsV1().StatefulSets("default").Create(statefulName)

// 更新 statefulUpdate
	statefulUpdate, err := clientset.AppsV1().StatefulSets("default").Update(statefulName)

// 删除 stateful
    err = clientset.AppsV1().StatefulSets("default").Delete("statefulName", &metav1.DeleteOptions{})
service
// 列出 serviceList
	serviceList, err := clientset.CoreV1().Services("default").List(metav1.ListOptions{})
 
// 查询 serviceGet
	serviceGet, err := clientset.CoreV1().Services("default").Get("web", metav1.GetOptions{})

// 创建 serviceCreate
	serviceCreate, err := clientset.CoreV1().Services("default").Create(web)

// 更新 serviceUpdate
	serviceUpdate, err := clientset.CoreV1().Services("default").Update(web)

// 删除 service
    err = clientset.CoreV1().Services.("default").Delete("serviceName", &metav1.DeleteOptions{})
ingress
// 列出 ingressList
	ingressList, err := clientset.ExtensionsV1beta1().Ingresses("default").List(metav1.ListOptions{})
 
// 查询 ingressGet
	ingressGet, err := clientset.ExtensionsV1beta1().Ingresses("default").Get("web", metav1.GetOptions{})

// 创建 ingressCreate
	ingressCreate, err := clientset.ExtensionsV1beta1().Ingresses("default").Create(web)

// 更新 ingressUpdate
	ingressUpdate, err := clientset.ExtensionsV1beta1().Ingresses("default").Update(web)

// 删除 ingress
    err = clientset.ExtensionsV1beta1().Ingresses("default").Delete("web", &metav1.DeleteOptions{})
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值