当前位置:网站首页>Simple integration of client go gin 11 delete
Simple integration of client go gin 11 delete
2022-06-25 04:05:00 【saynaihe】
background :
It's done client-go gin Simple integration of ten -Update, Let's demonstrate namespace deployment pod The deletion of , After the deletion is completed, you can also summarize and conduct more in-depth operations ! Delete from pod deployment namespace The sequence begins !
delete Pod
With nginx Pod For example
Be careful :zhangpeng namespace Next nginx pod For example
[[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
Write about pod delete Code for
Continue to imitate create update Write delete Method , Actually delete It only needs namespace and pod Of name That's all right. , To simplify the :
/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")
}
Add route run main.go
main.go Add route , And run main.go
r.POST("/pod/delete", service.DeletePod)
postman operation
http://127.0.0.1:8080/pod/delete
{"name":"nginx",
"namespace":"zhangpeng"}

delete deployment
With zhangpeng deployment For example
With namespace zhangpeng Under the namespace zhangpeng** deployment** For example
[[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
To write delete deployment Code
/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")
}
Add a route and run main.go
r.POST("/deployment/delete", service.DeleteDep)

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

delete namespace
With zhangpeng namespace For example
[[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
To write delete namespace Code
/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")
}
Add a route and run main.go
r.POST("/namespace/update", service.DeleteNameSpace)

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

summary
- client-go be based on gin Of curd It is basically realized
- What to achieve next
- More elegant output
- Extend the statefulset svc configmap And so on other k8s resources
- Sort out the types of data
- Extraction of methods , Sorting of public classes ? Organize the structure
边栏推荐
- Crawl Sina Weibo fans
- The problem that only the home page can be accessed under openSUSE Apache laravel
- Jilin University 22 spring March "automatic control principle" work assessment-00050
- Russian Airi Research Institute, etc. | SEMA: prediction of antigen B cell conformation characterization using deep transfer learning
- (超详细onenet TCP协议接入)arduino+esp8266-01s接入物联网平台,上传实时采集数据/TCP透传(以及lua脚本如何获取和编写
- NFT Insider #63:The Sandbox与时代杂志达成合作,YGG成立西班牙subDAO
- 《悉达多》:一生之书,可以时常反刍
- The era of copilot free is over! The official version is 67 yuan / month, and the student party and the defenders of popular open source projects can prostitute for nothing
- 如何使用IDE自动签名调试鸿蒙应用
- Mobile mall project operation
猜你喜欢

Time management understood after working at home | community essay solicitation

Redis related-01

Wuenda, the new course of machine learning is coming again! Free auditing, Xiaobai friendly

程序猿职业发展9项必备软技能

JSP cannot be resolved to a type error reporting solution

cesium 图形标注圆形、正方形、多边形、椭圆等

client-go gin的简单整合十一-Delete

Crawler grabs the idea of reading on wechat

2.吹响半音阶口琴

Crawler grabs the data of Douban group
随机推荐
Development of trading system (IX) -- dark pool technology
[rust submission] review impl trail and dyn trail in rust
【Harmony OS】【ArkUI】ets开发 图形与动画绘制
How far is the memory computing integrated chip from popularization? Listen to what practitioners say | collision school x post friction intelligence
MySQL根据表前缀批量修改、删除表
Zuckerberg's latest VR prototype is coming. It is necessary to confuse virtual reality with reality
Hello CTP (II) -- Introduction to CTP
[team learning] SQL programming language notes - task04
数学分析_笔记_第3章:极限
How to use crawlers to capture bullet screen and comment data of station B?
OpenSUSE environment PHP connection Oracle
Hello CTP (I) - basic knowledge of futures
La gamme NFT Color, qui représente la diversité, est en ligne sur la plate - forme du marché Sandbox
Development of trading system (I) -- Introduction to trading system
Jilin University 22 spring March "official document writing" assignment assessment-00084
Windows 2003 64 bit system PHP running error: 1% is not a valid Win32 Application
代表多样性的彩色 NFT 系列上线 The Sandbox 市场平台
居家办公之后才明白的时间管理 | 社区征文
AI writes its own code to let agents evolve! The big model of openai has the flavor of "human thought"
Jilin University 22 spring March document retrieval assignment assessment-00073