“Logs for postStart are not printing” 的翻译是 “postStart 的日志未打印”。

huangapple go评论101阅读模式
英文:

Logs for postStart are not printing

问题

我正在使用以下示例来测试 postStart 和 preStop 钩子。

apiVersion: v1
kind: Pod
metadata:
  name: aaaa
  labels:
    wwww: qqqq
spec:
  containers:
  - name: adassa
    image: nginx:1.10.1
    lifecycle:
      postStart:
        exec:
          command: ['bash', '-c', 'echo 11111111']
      preStop:
        exec:
          command: ['bash', '-c', 'echo 2222222']

我的 Pod 成功创建,但后来当我尝试使用 kubectl logs aaaa -c adassakubectl logs aaaa 来检查钩子的输出时,没有日志记录。

我尝试过但无法确定问题。我认为可能是 shell 的问题,所以我将 bash 更改为 sh,但之后甚至 Pod 都无法创建。

有人知道这里有什么问题吗?

英文:

I am using below example to test postStart and preStop hooks.

apiVersion: v1
kind: Pod
metadata:
  name: aaaa
  labels:
    wwww: qqqq
spec:
  containers:
  - name: adassa
    image: nginx:1.10.1
    lifecycle:
      postStart:
        exec:
          command: ['bash', '-c', 'echo 11111111']
      preStop:
        exec:
          command: ['bash', '-c', 'echo 2222222']

My pod was successfully created, but later when I tried to check the hooks output using kubectl logs aaaa -c adassa and kubectl logs aaaa then there were no logs.

I tried but not able to pinpoint the issue. I thought maybe shell issue, so I changed bash to sh but after this even Pod was not created.

Anyone has any idea what is wrong here?

答案1

得分: 1

PostStart 事件:

回显输出位于容器范围内,因此不显示/记录任何内容。
要执行命令,我使用:

> 命令:["/bin/sh", "-c", "echo 11111111> /tmp/message"]

有几种日志记录方法,但像上面那样写入文件是一个简单的示例,用于测试目的。

创建一个 Pod 后,执行交互式命令以获取 shell,最后检查生命周期触发是否以这种方式写入示例文件。

> kubectl exec -it aaaa -- /bin/bash
>
> cat /tmp/message

您应该得到:

> 11111111

参考指南以了解不同的日志记录方法,考虑使用第三方工具。

英文:

PostStart event:

The echo output is inside the container scope so it does not show/log anything.
For executing a command i use:

> command: ["/bin/sh", "-c", "echo 11111111> /tmp/message"]

There are several logging approaches however writing on a file as above is a simple example and for testing purposes.

Once you create a pod, execute interactive to get a shell and finally check if lifecycle trigger wrote on the sample file this way.

> kubectl exec -it aaaa -- /bin/bash
>
> cat /tmp/message

You should get:

> 11111111

Refer to this guide for different logging approaches, think about a 3rd party

huangapple
  • 本文由 发表于 2023年5月14日 04:39:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76244785.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定