kubernetes 尾车停止在边车吊舱中尾随(K8s)

fgw7neuy  于 2023-10-17  发布在  Kubernetes
关注(0)|答案(1)|浏览(101)

我正在跟踪A Cloud Guru的一个实验,在那里我必须创建一个Busybox容器写入日志文件,另一个Busybox映像阅读日志文件并将其输出到stdout
没有什么太难的,除了kubectl logs -f总是只返回日志的第一行,然后..没什么
我的Pod定义并没有什么特别的:

kind: Pod
metadata:
  name: logging-sidecar
  namespace: baz
spec:
  containers:
  - image: busybox
    name: logger
    command: ['sh', '-c', 'while true; do date > /output/output.log; sleep 5; done']
    volumeMounts:
    - name: share-vol
      mountPath: '/output'
  - image: busybox
    name: sidecar
    command: ['sh', '-c', 'tail -F /input/output.log']
    volumeMounts:
    - name: share-vol
      mountPath: '/input'
  volumes:
  - name: share-vol
    emptyDir: {}

实际上,创建日志文件的容器运行以下命令:

sh -c 'while true; do date > /output/output.log; sleep 5; done'

然后sidecar运行这个命令:

tail -F /input/output.log

当我将记录器更改为append>>)而不是overwrite>)时,一切都很好,每隔5秒,kubectl logs -f命令就会显示新的一行。
为什么tail -F选项在这里不起作用?
在这个特定的busybox版本(v1.36.1)中,tail命令是否存在问题?
sidecar更改为alpine图像的操作与上面相同;
然而,将图像更改为debian似乎可以解决问题,返回输出:

Sat Sep 16 17:38:07 UTC 2023
tail: /input/output.log: file truncated
Sat Sep 16 17:38:12 UTC 2023
tail: /input/output.log: file truncated
Sat Sep 16 17:38:17 UTC 2023
sg2wtvxw

sg2wtvxw1#

事实上-从man busybox

tail
tail [OPTIONS] [FILE]...

Print last 10 lines of each FILE to standard output. With more than one FILE, precede each with a header giving the file name. With no FILE, or when FILE is -, read standard input.

Options:

        -c N[kbm]       Output the last N bytes
        -n N[kbm]       Print last N lines instead of last 10
        -f              Output data as the file grows
        -q              Never output headers giving file names
        -s SEC          Wait SEC seconds between reads with -f
        -v              Always output headers giving file names
If the first character of N (bytes or lines) is a '+', output begins with the Nth item from the start of each file, otherwise, print the last N items in the file. N bytes may be suffixed by k (x1024), b (x512), or m (1024^2).

Busybox的tail没有跟踪截断文件的选项。

相关问题