kubectl logs command does not appear to respect --limit-bytes option

10/7/2019

When i issue

kubectl logs MY_POD_NAME --limit-bytes=1

command, the --limit-bytes option is ignored and i get all the pod's logs. My kubernetes version is 1.15.3 Trying to understand why that would be. When i issue the same command in GKE setup, the --limit-bytes option works as expected. I wonder what might be different in my setup to prevent this option from working correctly. (This is on CentOS).

Update: i tracked down the issue to Docker's --log-driver option. If the Docker --log-driver is set to 'json-file', then kubectl logs command works fine with --limit-bytes option. However, if the Docker -log-driver is set to 'journald', then kubectl logs command ignores the --limit-bytes option. Seems like a kubectl bug to me.

-- J.Doe
kubectl
kubernetes

2 Answers

10/8/2019

Yeah, it should work fine -

Please try this, if you have one container in application -

kubectl -n namespace logs pod_name --limit-bytes=1 

If you have multiple containers then please mention like -

kubectl -n namespace logs pod_name -c container_name --limit-bytes=1 
-- Tushar Mahajan
Source: StackOverflow

10/8/2019

After executing this command you shoud have seen following error:

error: expected 'logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]'.
POD or TYPE/NAME is a required argument for the logs command
See 'kubectl logs -h' for help and examples.

Execute:

$ kubectl logs your_pod_name  -c container_name --limit-bytes=1 -n namespace_name

If you set --limit-bytes flag you must know that --limit-bytes=0: Maximum bytes of logs to return.

Defaults to no limit.=0: Maximum bytes of logs to return. Defaults to no limit.

Documentation of kubectl-logs.

Please let me know if it helps.

-- MaggieO
Source: StackOverflow