从副本集中的特定容器获取所有日志

时间:2019-04-25 14:07:10

标签: kubernetes

如何从副本集中运行的特定容器中获取所有日志

我尝试了这个,但是没有用

kubectl logs -l=app={app-name},name={container-name} -n={namespace}

1 个答案:

答案 0 :(得分:3)

您需要使用 -c标志指定容器名称

kubectl logs -l=app={app-name} -c={container-name} -n={namespace}

您可以使用kubectl logs -h命令查看这些选项

Options:
      --all-containers=false: Get all containers's logs in the pod(s).
  -c, --container='': Print the logs of this container
  -f, --follow=false: Specify if the logs should be streamed.
      --limit-bytes=0: Maximum bytes of logs to return. Defaults to no limit.
      --pod-running-timeout=20s: The length of time (like 5s, 2m, or 3h, higher than zero) to wait until at least one
pod is running
  -p, --previous=false: If true, print the logs for the previous instance of the container in a pod if it exists.
  -l, --selector='': Selector (label query) to filter on.
      --since=0s: Only return logs newer than a relative duration like 5s, 2m, or 3h. Defaults to all logs. Only one of
since-time / since may be used.
      --since-time='': Only return logs after a specific date (RFC3339). Defaults to all logs. Only one of since-time /
since may be used.
      --tail=-1: Lines of recent log file to display. Defaults to -1 with no selector, showing all log lines otherwise
10, if a selector is provided.
      --timestamps=false: Include timestamps on each line in the log output