mar*_*pal 1 kubernetes kubectl
我正在研究 Kubernetes 集群上的自动化,并且需要创建一个 API 来封锁节点。基本上这个 API 不应该允许任何新的 pod 进入封锁节点。
我经历了下面的堆栈溢出讨论,但无法弄清楚封锁(然后排空)节点所需的 API: 如何在 Go 中访问 Kubernetes API 并运行 kubectl 命令
小智 6
为了找出特定 kubectl 命令中涉及的 API,请使用带有标志的 kubectl,该标志--v=9
显示向 API 服务器发出的 HTTP 请求及其响应(详细模式)
kubectl cordon nodename
:GET /api/v1/nodes/node-name
PATCH /api/v1/nodes/node-name
Run Code Online (Sandbox Code Playgroud)
在 HTTP PATCH 请求中,
Request Body: {"spec":{"unschedulable":true}}
Content-Type: "application/strategic-merge-patch+json"
在幕后,Golang 客户端将简单地进行类似的 HTTP 调用。请参阅此处在 golang 客户端中发出 HTTP PATCH 请求。
kubectl drain <nodename> --ignore-daemonsets
:PATCH /api/v1/nodes/node-name -> Request Body: {"spec":{"unschedulable":true}}
GET /api/v1/pods?fieldSelector=spec.nodeName%3Dnode-name -> Get Podlist
POST /api/v1/namespaces/kube-system/pods/coredns-7b5c8bfcfc-s94bs/eviction
GET /api/v1/namespaces/kube-system/pods/coredns-7b5c8bfcfc-s94bs -> If API call returns 404 means Pod is successfully evicted.
Run Code Online (Sandbox Code Playgroud)
基本上,drain 命令,首先封锁节点,然后从该节点驱逐 Daemonset Pod。
归档时间: |
|
查看次数: |
1651 次 |
最近记录: |