当前位置:网站首页>client-go gin的简单整合十一-Delete
client-go gin的简单整合十一-Delete
2022-06-25 03:44:00 【saynaihe】
背景:
完成了client-go gin的简单整合十-Update,下面演示一下namespace deployment pod的删除,删除完成了也可以总结一下进行更深入的操作了!删除就从pod deployment namespace的顺序开始了!
delete Pod
以nginx Pod为例
注意:zhangpeng namespace 下nginx pod为例
[[email protected] k8s]$ kubectl get pods -n zhangpeng
NAME READY STATUS RESTARTS AGE
nginx 1/1 Running 0 113s
zhangpeng-5546976d9-mkslb 1/1 Running 0 102m
zhangpeng-5546976d9-tcsb5 1/1 Running 0 101m
编写关于pod delete的代码
继续模仿create update 写delete方法,其实delete只需要namespace 和pod的name就可以了,简化一下:
/src/service/Pod.go
func DeletePod(g *gin.Context) {
var NewPod Pod
if err := g.ShouldBind(&NewPod); err != nil {
g.JSON(500, err)
}
err := K8sClient.CoreV1().Pods(NewPod.Namespace).Delete(context.TODO(), NewPod.Name, metav1.DeleteOptions{})
if err != nil {
fmt.Println(err)
}
g.JSON(200, "ok")
}
添加路由运行main.go
main.go增加路由,并运行main.go
r.POST("/pod/delete", service.DeletePod)
postman操作
http://127.0.0.1:8080/pod/delete
{"name":"nginx",
"namespace":"zhangpeng"}

delete deployment
以zhangpeng deployment为例
以namespace zhangpeng命名空间下zhangpeng** deployment**为例
[[email protected] k8s]$ kubectl get pods -n zhangpeng
NAME READY STATUS RESTARTS AGE
zhangpeng-5546976d9-mkslb 1/1 Running 0 124m
zhangpeng-5546976d9-tcsb5 1/1 Running 0 123m
[[email protected] k8s]$ kubectl get deployment -n zhangpeng
NAME READY UP-TO-DATE AVAILABLE AGE
zhangpeng 2/2 2 2 141m
编写delete deployment代码
/src/service/Deployment.go
func DeleteDep(g *gin.Context) {
var newDep Deployment
if err := g.ShouldBind(&newDep); err != nil {
g.JSON(500, err)
}
err := K8sClient.AppsV1().Deployments(newDep.Namespace).Delete(context.Background(), newDep.Name, metav1.DeleteOptions{})
if err != nil {
g.JSON(500, err)
}
g.JSON(200, "Deployment has delete")
}
添加路由并运行main.go
r.POST("/deployment/delete", service.DeleteDep)

postman测试
http://127.0.0.1:8080/deployment/delete
{"name":"zhangpeng",
"namespace":"zhangpeng"}

delete namespace
以zhangpeng namespace为例
[[email protected] k8s]$ kubectl get ns
NAME STATUS AGE
default Active 54d
kube-node-lease Active 54d
kube-public Active 54d
kube-system Active 54d
zhangpeng Active 21h
zhangpeng1 Active 24h
编写delete namespace代码
/src/service/Deployment.go
func DeleteDep(g *gin.Context) {
var newDep Deployment
if err := g.ShouldBind(&newDep); err != nil {
g.JSON(500, err)
}
err := K8sClient.AppsV1().Deployments(newDep.Namespace).Delete(context.Background(), newDep.Name, metav1.DeleteOptions{})
if err != nil {
g.JSON(500, err)
}
g.JSON(200, "Deployment has delete")
}
添加路由并运行main.go
r.POST("/namespace/update", service.DeleteNameSpace)

postman测试
http://127.0.0.1:8080/namespace/delete
{"name":"zhangpeng"}

总结
- client-go 基于gin 的curd算是基本实现
- 接下来要实现的
- 更优雅的输出
- 扩展一下statefulset svc configmap 等等其他k8s资源
- 数据的类型也的整理一下
- 方法的提取,公共类的整理?结构整理一下
边栏推荐
- Time management understood after working at home | community essay solicitation
- Do you really need automated testing?
- 騰訊開源項目「應龍」成Apache頂級項目:前身長期服務微信支付,能hold住百萬億級數據流處理...
- Sorting of poor cattle (winter vacation daily question 40)
- Randla net: efficient semantic segmentation of large scale point clouds
- Teach you how to install win11 system in winpe
- 马斯克被诉传销索赔2580亿美元,台积电公布2nm制程,中科院发现月壤中含有羟基形式的水,今日更多大新闻在此...
- JS tool function, self encapsulating a throttling function
- 俄罗斯AIRI研究院等 | SEMA:利用深度迁移学习进行抗原B细胞构象表征预测
- TensorFlow,危!抛弃者正是谷歌自己
猜你喜欢

Lao Ye's blessing

可能是拿反了的原因

Collaboration + Security + storage, cloud box helps Shenzhen edetai restructure its data center

服乔布斯不服库克,苹果传奇设计团队解散内幕曝光

Crawler grabs the data of Douban group

2点睡10点起不算熬夜?除非你每天都能执行

2022-06-21-Flink-49(一. SQL手册)

Redis related-03

Why can banana be a random number generator? Because it is the "king of radiation" in the fruit industry

Crawler grabs the idea of reading on wechat
随机推荐
Musk was sued for $258billion in MLM claims. TSMC announced the 2nm process. The Chinese Academy of Sciences found that the lunar soil contained water in the form of hydroxyl. Today, more big news is
Do you really need automated testing?
Sorting of poor cattle (winter vacation daily question 40)
Demonstration of combination of dream CAD cloud map and GIS
Wuenda, the new course of machine learning is coming again! Free auditing, Xiaobai friendly
Redis related-01
windows 2003 64位系统php运行报错:1% 不是有效的 win32 应用程序
OpenSUSE installation pit log
opencv怎么安装?opencv下载安装教程
Tencent's open source project "Yinglong" has become a top-level project of Apache: the former long-term service wechat payment can hold a million billion level of data stream processing
【组队学习】SQL编程语言笔记——Task04
Program. Launch (xxx) open file
Randla net: efficient semantic segmentation of large scale point clouds
How to use crawlers to capture bullet screen and comment data of station B?
The release function completed 02 "IVX low code sign in system production"
老叶的祝福
Google founder brin's second marriage broke up: it was revealed that he had filed for divorce from his Chinese wife in January, and his current fortune is $631.4 billion
Teach you how to install win11 system in winpe
Break the memory wall with CPU scheme? Learn from PayPal stack to expand capacity, and the volume of missed fraud transactions can be reduced to 1/30
js工具函数,自己封装一个节流函数