如何应用补丁使Pod阶段成功或失败? [英] How to apply patch to make pod phase go to Succeeded or Failed?

查看:79
本文介绍了如何应用补丁使Pod阶段成功或失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我最后一个问题的后续内容-如何以编程方式修改正在运行的k8s吊舱状态条件?我意识到,您只能修补部署清单中的容器规范,以使控制器通过其创建的ReplicaSet无缝地将修补程序更改应用到Pod.

现在我的问题是如何应用补丁程序使Pod阶段进入SucceededFailed.我知道例如为了使Pod阶段进入Succeeded,所有容器都需要成功终止,并且不应重新启动.我的意图是不修改容器映像中的原始命令和参数,而是应用补丁程序引入一个自定义命令,该命令将覆盖容器映像中的一个命令.

所以我尝试执行以下操作以按以下方式运行exit 0

 kubectl -n foo-ns patch deployment foo-manager -p '
{
  "spec": {
    "template": {
      "spec": {
        "containers": [
          {
            "name": "container1",
            "command": [
              "exit",
              "0"
            ]
          },
          {
            "name": "container2",
            "command": [
              "exit",
              "0"
            ]
          }
        ]
      }
    }
  }
}'
 

但是,由于我的容器文件系统层是从FROM scratch构建的,因此除了应该运行的原始可执行文件(即exit)以外,没有任何本机命令可用,因为甚至没有内置的.

执行此操作的最佳方法是什么?通过修补Pod使其过渡到这两个Pod阶段中的任何一个阶段.

解决方案

如何应用补丁程序使Pod阶段成功或失败

Pod旨在为不可变-请勿尝试对其进行更改-而是将其替换为新的Pod.您可以直接创建 ReplicaSet ,但是大多数情况下,您希望使用<一个href ="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/" rel ="nofollow noreferrer">部署,它将为Pod模板上的每个更改替换当前的ReplicaSet.

基本上我正在测试我的一个自定义控制器,当它处于某种状态时,它可以捕获Pod的相位(并对其进行操作).待处理

所有Pod都经过这些状态.为了进行测试,您可以直接使用不同的二进制文件或参数创建 Pod . >

要测试Pod阶段Pending,可以在观看Pod时在控制器中记录 phase ?或者您可以嘲笑吊舱-使其处于待处理"阶段?

我不知道 kubernetes-python-client ,但是client-go确实有问题#524假客户进行单元测试

This is a follow-up from my last question - How to programmatically modify a running k8s pod status conditions? after which I realized, you can only patch the container spec from the deployment manifest to seamlessly let the controller apply the patch changes to the pods through the ReplicaSet it created.

Now my question is how to apply patch to make the Pod phase to go to Succeeded or Failed. I know for e.g. for pod phase to go to Succeeded, all the containers need to terminate successfully and shouldn't be restarted. My intention is to not modify the original command and arguments from the container image, but apply a patch to introduce a custom command which will override the one from the container image.

So I attempted to do below to run exit 0 as below

kubectl -n foo-ns patch deployment foo-manager -p '
{
  "spec": {
    "template": {
      "spec": {
        "containers": [
          {
            "name": "container1",
            "command": [
              "exit",
              "0"
            ]
          },
          {
            "name": "container2",
            "command": [
              "exit",
              "0"
            ]
          }
        ]
      }
    }
  }
}'

But since my container file system layers are built from FROM scratch, there aren't any native commands available other than the original executable supposed to run i.e. exit as a built-in is not even available.

What's the best way to do this? by patching the pod to make it transition to either of those Pod phases.

解决方案

how to apply patch to make the Pod phase to go to Succeeded or Failed

Pods are intended to be immutable - don't try to change them - instead, replace them with new Pods. You can create ReplicaSet directly, but mostly, you want to work with Deployment that is replacing the current ReplicaSet for every change on the Pod-template.

Basically I'm testing one of my custom controllers can catch a pod's phase (and act on it) when it is stuck in a certain state e.g. Pending

All Pods goes through those states. For testing, you can create Pods directly, with different binaries or arguments.

To test Pod phase Pending you could, log the phase in your controller when watching a Pod? Or you can mock the pod - so that it is in phase Pending?

I don't know kubernetes-python-client but client-go does have Fake-clients that can work with Pods, including UpdateStatus.

func (c *FakePods) UpdateStatus(ctx context.Context, pod *corev1.Pod, opts v1.UpdateOptions) (*corev1.Pod, error)

Now, looking at the Python client, it does seem to lack this feature: Issue #524 fake client for unit testing

这篇关于如何应用补丁使Pod阶段成功或失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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