Nada Nour:
Hi All,
when i try to configure logging using sidecar as in the below link, i get this error on the container
controlplane $ kubectl logs webapp-1 count-log-1
tail: can’t open ‘/var/log/1.log’: No such file or directory
tail: no files
https://kubernetes.io/docs/concepts/cluster-administration/logging/#using-a-sidecar-container-with-the-logging-agent
Tej_Singh_Rana:
Hello, @Nada Nour
Can you please share your yaml file?
Nada Nour:
spec:
containers:
- image: busybox
imagePullPolicy: Always
name: simple-webapp
args:
- /bin/sh
- -c
- >
i=0;
while true;
do
echo "$i: $(date)" >> /var/log/1.log;
echo "$(date) INFO $i" >> /var/log/2.log;
i=$((i+1));
sleep 1;
done
ports:
- containerPort: 8080
protocol: TCP
volumeMounts:
- name: varlog
mountPath: /var/log
- name: count-log-1
image: busybox
args: [/bin/sh, -c, 'tail -n+1 -f /var/log/1.log']
volumeMounts:
- name: varlog
mountPath: /var/log
volumes:
- name: varlog
emptyDir: {}
Tej_Singh_Rana:
Hello, @Nada Nour
It’s working fine.
controlplane $ kubectl logs loger
error: a container name must be specified for pod loger, choose one of: [simple-webapp count-log-1]
controlplane $ kubectl logs loger count-log-1
0: Tue Dec 22 10:48:08 UTC 2020
1: Tue Dec 22 10:48:09 UTC 2020
2: Tue Dec 22 10:48:10 UTC 2020
3: Tue Dec 22 10:48:11 UTC 2020
4: Tue Dec 22 10:48:12 UTC 2020
5: Tue Dec 22 10:48:13 UTC 2020
6: Tue Dec 22 10:48:14 UTC 2020
7: Tue Dec 22 10:48:15 UTC 2020
8: Tue Dec 22 10:48:16 UTC 2020
9: Tue Dec 22 10:48:17 UTC 2020
10: Tue Dec 22 10:48:18 UTC 2020
11: Tue Dec 22 10:48:19 UTC 2020
12: Tue Dec 22 10:48:20 UTC 2020
13: Tue Dec 22 10:48:21 UTC 2020
14: Tue Dec 22 10:48:22 UTC 2020
15: Tue Dec 22 10:48:23 UTC 2020
16: Tue Dec 22 10:48:24 UTC 2020
17: Tue Dec 22 10:48:25 UTC 2020
18: Tue Dec 22 10:48:26 UTC 2020
19: Tue Dec 22 10:48:27 UTC 2020
20: Tue Dec 22 10:48:28 UTC 2020
21: Tue Dec 22 10:48:29 UTC 2020
22: Tue Dec 22 10:48:30 UTC 2020
23: Tue Dec 22 10:48:31 UTC 2020
24: Tue Dec 22 10:48:32 UTC 2020
25: Tue Dec 22 10:48:33 UTC 2020
controlplane $ kubectl get po
NAME READY STATUS RESTARTS AGE
loger 2/2 Running 0 52s
Tej_Singh_Rana:
I haven’t seen any issue with your yaml file.
Tej_Singh_Rana:
kind: Pod
apiVersion: v1
metadata:
name: loger
labels:
app: loger
spec:
containers:
- image: busybox
imagePullPolicy: Always
name: simple-webapp
args:
- /bin/sh
- -c
- >
i=0;
while true;
do
echo "$i: $(date)" >> /var/log/1.log;
echo "$(date) INFO $i" >> /var/log/2.log;
i=$((i+1));
sleep 1;
done
ports:
- containerPort: 8080
protocol: TCP
volumeMounts:
- name: varlog
mountPath: /var/log
- name: count-log-1
image: busybox
args: [/bin/sh, -c, 'tail -n+1 -f /var/log/1.log']
volumeMounts:
- name: varlog
mountPath: /var/log
volumes:
- name: varlog
emptyDir: {}
Nada Nour:
strange, yes pod created and in Error state
AB:
run kubectl describe pod
Nada Nour:
Events:
Type Reason Age From Message
Normal Pulling 14s kubelet, node01 Pulling image “busybox”
Normal Pulled 13s kubelet, node01 Successfully pulled image “busybox” in 1.049768654s
Normal Created 12s kubelet, node01 Created container simple-webapp
Normal Started 12s kubelet, node01 Started container simple-webapp
Normal Pulled 12s kubelet, node01 Successfully pulled image “busybox” in 609.721394ms
Normal Pulling 11s (x2 over 12s) kubelet, node01 Pulling image “busybox”
Normal Created 10s (x2 over 12s) kubelet, node01 Created container count-log-1
Normal Pulled 10s kubelet, node01 Successfully pulled image “busybox” in 886.190791ms
Normal Started 9s (x2 over 11s) kubelet, node01 Started container count-log-1
Warning BackOff 7s (x2 over 8s) kubelet, node01 Back-off restarting failed container
Nada Nour:
when i copy paste the pod from the link it works but when i add the sidecar container i get this error