Kubernetes Docker logs

0 votes

I'm trying to check kubernetes logs on docker, using the following command:

kubectl logs pod_name -n namespace

it prints all the logs from the start

  1. Is there anyway to tail the logs or check logs between the given window?
  2. Is it possible to rotate docker logs based on size or date?
Aug 28, 2018 in Kubernetes by lina
• 8,220 points
850 views

2 answers to this question.

0 votes

1) yes, you can tail or filter by date.

As easy as running

kubectl logs --help
Options:
  -c, --container='': Print the logs of this container
  -f, --follow=false: Specify if the logs should be streamed.
      --include-extended-apis=true: If true, include definitions of new APIs via calls to the API server. [default true]
      --interactive=false: If true, prompt the user for input when required.
      --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

2) Docker stores the container logs in host in the path /var/lib/docker/containers/{ContainerId} so you could copy/truncate the logs directly.

answered Aug 28, 2018 by Kalgi
• 52,350 points
0 votes

To tail the logs, use the -foption

kubectl logs pod_name -n namespace -f

You can query logs x-lines ago or since a time range. Take a look at the —tail and —since options

answered Sep 6, 2018 by Nilesh
• 7,060 points

Related Questions In Kubernetes

0 votes
1 answer

Accessing private Docker Hub repository from Kubernetes on Vagrant

In order to pull private dockerhub hosted ...READ MORE

answered Sep 18, 2018 in Kubernetes by DareDev
• 6,890 points
1,465 views
0 votes
1 answer

Cannot connect unix:///var/run/docker.sock in kubernetes using GitLab CI runner

Do not use this: DOCKER_DRIVER: overlay because OVERLAY is ...READ MORE

answered Oct 16, 2018 in Kubernetes by DareDev
• 6,890 points
3,498 views
0 votes
1 answer

Kubernetes: Unable to get services in namespace: logs"system:serviceaccount:default:default"

Your approach is wrong here. Namespace is ...READ MORE

answered Oct 27, 2018 in Kubernetes by ajs3033
• 7,300 points
7,522 views
+2 votes
1 answer
+5 votes
7 answers

Docker swarm vs kubernetes

Swarm is easy handling while kn8 is ...READ MORE

answered Aug 27, 2018 in Docker by Mahesh Ajmeria
3,925 views
0 votes
1 answer

image can't be pulled error when I try to pull a docker image - kubernetes

I think the image is being pulled ...READ MORE

answered Sep 4, 2018 in Kubernetes by Kalgi
• 52,350 points
6,205 views
0 votes
1 answer

nnot set docker credentials on kubernetes AWS

The best method for you is ImagePullSecrets - you ...READ MORE

answered Oct 9, 2018 in Kubernetes by Kalgi
• 52,350 points
562 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP