当前位置:网站首页>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
边栏推荐
- Development of trading system (IX) -- dark pool technology
- Work assessment of Biopharmaceutics of Jilin University in March of the 22nd spring -00031
- Zuckerberg's latest VR prototype is coming. It is necessary to confuse virtual reality with reality
- JS tool function, self encapsulating a throttling function
- Development of trading system (VII) -- Analysis of trading delay
- Tensorflow, danger! Google itself is the one who abandoned it
- Cesium 拖拽3D模型
- Development of trading system (VI) -- HFT high frequency trading
- Comprehensive assignment of thesis writing instruction of Dongcai
- Hello CTP (IV) - CTP transaction API
猜你喜欢

Development of trading system (VIII) -- Construction of low delay network

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

Tensorflow, danger! Google itself is the one who abandoned it
![[rust submission] review impl trail and dyn trail in rust](/img/bc/05b3e031659ce19d6f6e3887d70512.jpg)
[rust submission] review impl trail and dyn trail in rust

【Proteus仿真】Arduino UNO按键控制数码管闪烁增/减显示

Crawler crawls Sina Weibo data

Redis related-01

Russian Airi Research Institute, etc. | SEMA: prediction of antigen B cell conformation characterization using deep transfer learning

(ultra detailed onenet TCP protocol access) arduino+esp8266-01s accesses the Internet of things platform, uploads real-time collected data /tcp transparent transmission (and how to obtain and write Lu

【Harmony OS】【ARK UI】ETS 上下文基本操作
随机推荐
Jilin University 22 spring March new development English comprehensive course (I) assignment assessment-00080
论一个优秀红队人员的自我修养
opencv怎么安装?opencv下载安装教程
一文搞懂php中的(DI)依赖注入
居家办公之后才明白的时间管理 | 社区征文
Work assessment of Biopharmaceutics of Jilin University in March of the 22nd spring -00031
俄罗斯AIRI研究院等 | SEMA:利用深度迁移学习进行抗原B细胞构象表征预测
zabbix的安装避坑指南
墨天轮访谈 | IvorySQL王志斌—IvorySQL,一个基于PostgreSQL的兼容Oracle的开源数据库
Cesium 加载显示热力图
Teach you how to install win11 system in winpe
教你如何在winpe里安装win11系统
Jilin University 22 spring March "official document writing" assignment assessment-00084
AI quantitative transaction (I) -- Introduction to quantitative transaction
2. play the chromatic harmonica
微信小程序中的列表渲染
Development of trading system (V) -- Introduction to Sinovel counter
Cesium loading display thermal diagram
【Harmony OS】【ARK UI】ETS 上下文基本操作
Solution to the problem that Linux crontab timed operation Oracle does not execute (crontab environment variable problem)