当前位置:网站首页>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
边栏推荐
- 【组队学习】SQL编程语言笔记——Task04
- Hello CTP (I) - basic knowledge of futures
- Preparedstatement principle of preventing SQL injection
- client-go gin的简单整合十一-Delete
- Crawler grabs the data of Douban group
- BSC parsing input data of transaction
- 智慧风电:数字孪生 3D 风机智能设备运维
- 2D 照片变身 3D 模型,来看英伟达的 AI 新“魔法”!
- Peking University has a new president! Gongqihuang, academician of the Chinese Academy of Sciences, took over and was admitted to the Physics Department of Peking University at the age of 15
- Tensorflow, danger! Google itself is the one who abandoned it
猜你喜欢
Crawl Sina Weibo fans
2.吹响半音阶口琴
Mobile mall project operation
How to use ide to automatically sign and debug Hongmeng application
Lao Ye's blessing
Cesium 加载显示热力图
墨天轮访谈 | IvorySQL王志斌—IvorySQL,一个基于PostgreSQL的兼容Oracle的开源数据库
《Missing Parts》NFT 作品集第 5 系列上线 The Sandbox 市场平台
《悉达多》:一生之书,可以时常反刍
Crawler grabs the idea of reading on wechat
随机推荐
严重的PHP缺陷可导致QNAP NAS 设备遭RCE攻击
Preparedstatement principle of preventing SQL injection
Hello CTP (I) - basic knowledge of futures
(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
opencv是开源的吗?
uniapp 制作手机app程序, 使用uni.chooseVideo录制视频,视频播放模糊分辨率低的原因
Deveco studio 3.0 editor configuration tips
长沙“求才”:“下力气”与“出实招”并进,“快发展”和“慢生活”兼得
Zuckerberg's latest VR prototype is coming. It is necessary to confuse virtual reality with reality
Comprehensive assignment of thesis writing instruction of Dongcai
What is the difference between learning code, rolling code and fixed code? The number of repeated codes, coding capacity and the principle of rolling code
Time management understood after working at home | community essay solicitation
Crawler grabs the idea of reading on wechat
Development of trading system (x) -- fix agreement
Development of trading system (III) - risk control system
Cesium graphic annotation circle, square, polygon, ellipse, etc
Qt编译数据库插件通用步骤说明
The more AI evolves, the more it resembles the human brain! Meta found the "prefrontal cortex" of the machine. AI scholars and neuroscientists were surprised
Musk: Twitter should learn from wechat and make 1billion people "live on it" into a super app
Now, the ear is going into the metauniverse