如何以编程方式修改正在运行的K8S吊舱状态条件? [英] How to programmatically modify a running k8s pod status conditions?

查看:69
本文介绍了如何以编程方式修改正在运行的K8S吊舱状态条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过部署控制器(通过kubectl patch从命令行和k8s python客户端API)来修改我的pod的运行状态,该部署控制器由部署控制器进行管理.他们俩似乎都不起作用

I'm trying to modify the running state of my pod, managed by a deployment controller both from command line via kubectl patch and from the k8s python client API. Neither of them seem to work

在命令行中,我尝试了战略合并匹配和JSON合并补丁,但是它们都不起作用.例如我正在尝试修补吊舱条件,以将status字段设置为False

From the command line, I tried both strategic merge match and JSON merge patch, but neither of them works. For e.g. I'm trying to patch the pod conditions to make the status field to False

kubectl -n foo-ns patch pod foo-pod-18112 -p '{
  "status": {
    "conditions": [
      {
        "type": "PodScheduled",
        "status": "False"
      },
      {
        "type": "Ready",
        "status": "False"
      },
      {
        "type": "ContainersReady",
        "status": "False"
      },
      {
        "type": "Initialized",
        "status": "False"
      }
    ],
    "phase": "Running"
  }
}' --type merge

通过python API

From the python API

# definition of various pod states
ready_true        = { "type": "Ready", "status": "True" }
ready_false       = { "type": "Ready", "status": "False" }
scheduled_true    = { "type": "PodScheduled", "status": "True" }
cont_ready_true   = { "type": "ContainersReady", "status": "True" }
cont_ready_false  = { "type": "ContainersReady", "status": "False" }
initialized_true  = { "type": "Initialized", "status": "True" }
initialized_false = { "type": "Initialized", "status": "False" }

patch = {"status": { "conditions": [ready_false, initialized_false, cont_ready_false, scheduled_true ], "phase" : "Running" }}

p_status = v1.patch_namespaced_pod_status(podname, "default",  body=patch)

在运行上述代码段时,我没有看到任何错误,并且响应p_status修改了patch中应用的所有pod条件,但是我没有看到来自API服务器的与此相关的任何事件广告连播状态更改.

While running the above snippet, I don't see any errors and the response p_status has all the pod conditions modified as applied in the patch, but I don't see any events from API server related to this pod status change.

部署控制器是否会将更改回滚到工作配置?我正在寻找修补广告连播条件的方法,并测试我的自定义控制器(与问题无关)是否能够看到这些新的广告连播条件.

May be the deployment controller is rolling back the changes to a working config? I'm looking for ways to patch the pod conditions and test if my custom controller (not related to the question) is able to see those new pod conditions.

推荐答案

您不应该.

客户端在spec:中编写所需状态,而控制器在status:部分中编写.

Clients write the desired state in the spec: and controllers write the status:-part.

这篇关于如何以编程方式修改正在运行的K8S吊舱状态条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆