I have a requirement to extract my application log which is available under /var/etc/logs directory. How do I extract this from K8 pods?
Tried kubectl exec but didnt help.
You might need a log collector like fluentd.
k8s itself won't persist log for you.
If you are using GKE, stackdriver might be an approach (heard, never tried).
The purest and simplest way to get the application log from your pod is using kubectl cp
kubectl cp <pod-name>:/var/etc/logs logs
This will copy the pod logs to your local machine.
However..
That's probably not a good long term solution. I'd recommend:
kubectl logs
would become availabla ro youMore information can be found here
Besides the Fluentd
sidecar option described in the other answers, you can also add simple tail -n+1 -f /var/etc/logs
sidecar to output your logs to stdout:
apiVersion: v1
kind: Pod
metadata:
name: mypod
spec:
containers:
- name: container
image: yourimage
volumeMounts:
- name: varlog
mountPath: /var/log
- name: logs
image: busybox
args: [/bin/sh, -c, 'tail -n+1 -f /var/etc/logs']
volumeMounts:
- name: varlog
mountPath: /var/log
volumes:
- name: varlog
emptyDir: {}