0

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.

4

1 回答 1

3

如何应用补丁使 Pod 阶段进入成功或失败

Pod 旨在是不可变的——不要试图改变它们——而是用新的 Pod 替换它们。您可以直接创建ReplicaSet,但大多数情况下,您希望使用为 Pod 模板上的每次更改替换当前 ReplicaSet 的Deployment 。

基本上,我正在测试我的一个自定义控制器可以在 Pod 卡在某个状态(例如 Pending)时捕获它的阶段(并对其采取行动)

所有 Pod 都会经过这些状态。对于测试,您可以使用不同的二进制文件或参数直接创建Pod 。

要测试 Pod 阶段,您可以在观看 Pod 时在控制器中Pending记录阶段?或者您可以模拟 pod - 使其处于 Pending 阶段?

我不知道kubernetes-python-clientclient-go确实有可以与 Pod 一起使用的Fake-clients,包括UpdateStatus.

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

现在,查看 Python 客户端,它似乎确实缺少此功能:Issue #524 fake client for unit testing

于 2020-11-18T18:18:11.100 回答