Get all Logs from a specific container in a replica set

4/25/2019

How can I get all the logs from a specific container(s) that are running in a replica set

I tried this but it's not working

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

1 Answer

4/25/2019

You need to use -c flag to specify the Container name

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

As you can see the options with the kubectl logs -h command

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
-- Suresh Vishnoi
Source: StackOverflow