This article explains the log collection techniques for contrail releases post 5.0
Application and systems logs can help you understand what is happening inside your cluster. The easiest and most embraced logging method for containerized applications is to write to the standard output and standard error streams. The logs are particularly useful for debugging problems and monitoring cluster activity.
-o=custom-columns= <spec>
-o=custom-columns-file= <filename>
-o=jsonpath= <template>
-o=jsonpath-file= <filename>
-o=name
-o=wide
-o=yaml
–output-format usage
kubectl get pod -o json -n contrail |jq -r .items[].status.podIP
kubectl get pods --all-namespaces -o=jsonpath='{range .items[*]}{"\n"}{.metadata.name}{":\t"}{range .spec.containers[*]}{.image}{", "}{END.EN_US}{END.EN_US}'
contrail-analytics-8lsbx: docker.io/opencontrailnightly/contrail-analytics-api:latest, docker.io/opencontrailnightly/contrail-analytics-collector:latest, docker.io/opencontrailnightly/contrail-analytics-alarm-gen:latest, docker.io/opencontrailnightly/contrail-analytics-query-engine:latest, docker.io/opencontrailnightly/contrail-nodemgr:latest, contrail-analytics-zookeeper-s4xdj: docker.io/opencontrailnightly/contrail-external-zookeeper:latest, contrail-analyticsdb-nodemgr-9vqbr: docker.io/opencontrailnightly/contrail-nodemgr:latest, contrail-analyticsdb-xg76d: docker.io/opencontrailnightly/contrail-external-cassandra:latest, contrail-config-g9fn7: docker.io/opencontrailnightly/contrail-controller-config-api:latest, docker.io/opencontrailnightly/contrail-controller-config-devicemgr:latest, docker.io/opencontrailnightly/contrail-controller-config-schema:latest, docker.io/opencontrailnightly/contrail-controller-config-svcmonitor:latest, docker.io/opencontrailnightly/contrail-nodemgr:latest, contrail-config-zookeeper-swmrt: docker.io/opencontrailnightly/contrail-external-zookeeper:latest, contrail-configdb-cnwzb: docker.io/opencontrailnightly/contrail-external-cassandra:latest, contrail-control-56p7r: docker.io/opencontrailnightly/contrail-controller-control-control:latest, docker.io/opencontrailnightly/contrail-controller-control-dns:latest, docker.io/opencontrailnightly/contrail-controller-control-named:latest, docker.io/opencontrailnightly/contrail-nodemgr:latest, contrail-kafka-f4xkb: docker.io/opencontrailnightly/contrail-external-kafka:latest, contrail-redis-pggmc: redis:4.0.2, contrail-vrouter-agent-kernel-f92x5: docker.io/opencontrailnightly/contrail-vrouter-agent:latest, docker.io/opencontrailnightly/contrail-nodemgr:latest, contrail-webui-hjgzk: docker.io/opencontrailnightly/contrail-controller-webui-job:latest, docker.io/opencontrailnightly/contrail-controller-webui-web:latest, ingress-68bdd5bf66-n9n7h: quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.9.0, ingress-error-pages-f57f86986-fb47t: gcr.io/google_containers/defaultbackend:1.0,
kubectl get pod -o=custom-columns=Namespace:.metadata.namespace,PODS:.metadata.name,CONTAINERS:.spec.containers[*].name -n contrail
Namespace PODS CONTAINERS contrail contrail-analytics-8lsbx contrail-analytics-api,contrail-collector,contrail-alarm-gen,contrail-query-engine,contrail-analytics-nodemgr contrail contrail-analytics-zookeeper-s4xdj zookeeper contrail contrail-analyticsdb-nodemgr-9vqbr contrail-analyticsdb-nodemgr contrail contrail-analyticsdb-xg76d contrail-analyticsdb contrail contrail-config-g9fn7 contrail-config-api,contrail-devicemgr,contrail-schema-transformer,contrail-svcmonitor,contrail-config-nodemgr contrail contrail-config-zookeeper-swmrt zookeeper contrail contrail-configdb-cnwzb contrail-configdb contrail contrail-control-56p7r contrail-control,contrail-dns,contrail-named,contrail-control-nodemgr contrail contrail-kafka-f4xkb kafka contrail contrail-redis-pggmc redis contrail contrail-vrouter-agent-kernel-f92x5 contrail-vrouter-agent,contrail-vrouter-nodemgr contrail contrail-webui-hjgzk contrail-webui-middleware,contrail-webui contrail ingress-68bdd5bf66-n9n7h ingress contrail ingress-error-pages-f57f86986-fb47t ingress-error-pages
kubectl get pod -n contrail -o=custom-columns-file=template
NAME Containers contrail-analytics-8lsbx contrail-analytics-api,contrail-collector,contrail-alarm-gen,contrail-query-engine,contrail-analytics-nodemgr contrail-analytics-zookeeper-s4xdj zookeeper contrail-analyticsdb-nodemgr-9vqbr contrail-analyticsdb-nodemgr contrail-analyticsdb-xg76d contrail-analyticsdb contrail-config-g9fn7 contrail-config-api,contrail-devicemgr,contrail-schema-transformer,contrail-svcmonitor,contrail-config-nodemgr contrail-config-zookeeper-swmrt zookeeper contrail-configdb-cnwzb contrail-configdb contrail-control-56p7r contrail-control,contrail-dns,contrail-named,contrail-control-nodemgr contrail-kafka-f4xkb kafka contrail-redis-pggmc redis contrail-vrouter-agent-kernel-f92x5 contrail-vrouter-agent,contrail-vrouter-nodemgr contrail-webui-hjgzk contrail-webui-middleware,contrail-webui ingress-68bdd5bf66-n9n7h ingress ingress-error-pages-f57f86986-fb47t ingress-error-pages root@ubuntu1604:~# root@ubuntu1604:~# root@ubuntu1604:~# cat template NAME Containers metadata.name spec.containers[*].name
kubectl get pods --sort-by=.metadata.name -n contrail
NAME READY STATUS RESTARTS AGE contrail-analytics-8lsbx 5/5 Running 0 37d contrail-analytics-zookeeper-s4xdj 1/1 Running 0 37d contrail-analyticsdb-nodemgr-9vqbr 1/1 Running 0 37d contrail-analyticsdb-xg76d 1/1 Running 0 37d contrail-config-g9fn7 5/5 Running 0 37d contrail-config-zookeeper-swmrt 1/1 Running 0 37d contrail-configdb-cnwzb 1/1 Running 0 37d contrail-control-56p7r 4/4 Running 0 37d contrail-kafka-f4xkb 1/1 Running 0 37d contrail-redis-pggmc 1/1 Running 0 37d contrail-vrouter-agent-kernel-f92x5 2/2 Running 1 37d contrail-webui-hjgzk 2/2 Running 0 37d ingress-68bdd5bf66-n9n7h 1/1 Running 0 37d ingress-error-pages-f57f86986-fb47t 1/1 Running 0 37d
Everything contained in Kubernetes is represented by a RESTful resource. We refer to these resources as Kubernetes objects. Each Kubernetes object exists at a unique HTTP path.
The kubectl command makes HTTP requests to these URLs to access the Kubernetes objects that reside at these paths.
$ kubectl logs <pod-name>
If you have multiple containers in your pod you can choose the container to view using the -c flag.
Kubernetes provides two commands for debugging running containers. The kubectl logs command downloads the current logs from the running instance:
Adding the -f flag will cause you to continuously stream logs.
The kubectl logs command always tries to get logs from the currently running container. Adding the --previous flag will get logs from a previous instance of the container. This is useful, for example, if your containers are continuously restarting due to a problem at container startup.
root@ubuntu1604:~# kub logs contrail-vrouter-agent-kernel-f92x5 -c contrail-vrouter-agent -n contrail --previous
INFO: agent started in kernel mode Device "vhost0" does not exist. cat: /sys/class/net/vhost0/address: No such file or directory INFO: creating vhost0 for nic mode: nic: ens4, mac=52:54:00:4b:b8:76 INFO: there is no ifcfg-ens4 a nd ifcfg-vhost0, so initialize vhost0 manually INFO: Changing physical interface to vhost in ip table RTNETLINK answers: File exists ERROR: failed to add address fe80::5054:ff:fe4b:b876/64 to vhost0. INFO: set default gateway ERROR: failed to add default gateway 10.168.6.1 INFO: set mtu FATAL: failed to init vhost0 RTNETLINK answers: File exists
Usage:
kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER] [options]
Examples:
kubectl logs contrail-redis-pggmc -n contrail
kubectl logs -lapp=nginx
kubectl logs --tail=20 nginx
kubectl logs --since=1h nginx
kubectl logs deployment/nginx -c nginx-1
kubectl logs my-pod
kubectl logs my-pod --previous
kubectl logs my-pod -c my-container
kubectl logs my-pod -c my-container --previous
kubectl logs -f my-pod
kubectl logs -f my-pod -c my-container
kubectl run -i --tty busybox --image=busybox -- sh
kubectl attach my-pod -i
kubectl exec my-pod -- ls /
kubectl exec my-pod -c my-container -- ls /
-v
--v
--v=0
--v=1
--v=2
--v=3
--v=4
--v=6
--v=7
--v=8
--v=9
root@ubuntu1604:~# kubectl exec -it contrail-vrouter-agent-kernel-f92x5 -c contrail-vrouter-agent -n contrail -- tail -f /var/log/contrail/contrail-vrouter-agent.log 2018-07-27 Fri 01:15:01:401.876 UTC ubuntu1604 [Thread 139678473840384, Pid 166]: SANDESH: Send FAILED: 1532654101401758 [SYS_INFO]: XmppConnectionLog: connection= [ ip_address = 10.168.6.9 state = Idle next_state = Active event = Start ] file = controller/src/xmpp/xmpp_state_machine.cc line = 1706 2018-07-27 Fri 01:15:01:402.003 UTC ubuntu1604 [Thread 139678473840384, Pid 166]: SANDESH: Send FAILED: 1532654101401832 [SYS_NOTICE]: NodeStatusUVE: data= [ name = ubuntu1604 process_status= [ [ [ module_id = contrail-vrouter-agent instance_id = 0 state = Non-Functional connection_infos= [ [ [ type = XMPP name = control-node:10.168.6.9 server_addrs= [ [ (*_iter6) = 10.168.6.9:5269, ] ] status = Down description = Idle ], [ type = Collector name = server_addrs= [ [ (*_iter6) = 172.17.0.1:8086, ] ] status = Initializing description = Disconnect : EvCollectorUpdate -> Connect ], ] ] description = XMPP:control-node:10.168.6.9, Collector connection down, No Configuration for self Number of connections:2, Expected: 3 ], ] ] ]
kubectl cluster-info dump > file
Copying Files to and from Containers
At times you may need to copy files from a remote container to a local machine for more in-depth exploration. For example, you can use a tool like Wireshark to visualize tcpdump packet captures. Suppose you had a file called /captures/capture3.txt inside a container in your Pod. You could securely copy that file to your local machine by running:
$ kubectl cp <pod-name> :/captures/capture3.txt ./capture3.txt
Other times you may need to copy files from your local machine into a container. Let’s say you want to copy $HOME/config.txt to a remote container. In this case, you can run:
$ kubectl cp $HOME/config.txt <pod-name> :/config.txt
kubectl get pods --sort-by='.status.containerStatuses[0].restartCount' kubectl top pod contrail-vrouter-agent-kernel-f92x5 --containers -n contrail
root@ubuntu1604:~# docker ps -a|grep vrouter d348c988cdce opencontrailnightly/contrail-vrouter-agent@sha256:ede65841bf277479b982310aa6423e9a987d7a1e001e97ea753fb549e5597ce4 "/entrypoint.sh /u..." 3 months ago Up 3 months k8s_contrail-vrouter-agent_contrail-vrouter-agent-kernel-f92x5_contrail_722cdf8d-9138-11e8-976a-525400db35a1_1 adf22040454d opencontrailnightly/contrail-nodemgr@sha256:d09d687e0d3b91b53679ebd20441414eb3ac07b0555a0036939f60153d7cb2ba "/entrypoint.sh /b..." 3 months ago Up 3 months k8s_contrail-vrouter-nodemgr_contrail-vrouter-agent-kernel-f92x5_contrail_722cdf8d-9138-11e8-976a-525400db35a1_0 fef46544c6cc opencontrailnightly/contrail-vrouter-agent@sha256:ede65841bf277479b982310aa6423e9a987d7a1e001e97ea753fb549e5597ce4 "/entrypoint.sh /u..." 3 months ago Exited (1) 3 months ago k8s_contrail-vrouter-agent_contrail-vrouter-agent-kernel-f92x5_contrail_722cdf8d-9138-11e8-976a-525400db35a1_0 a94337399549 opencontrailnightly/contrail-vrouter-kernel-build-init@sha256:52582975874f16841056cf7915303dd132bcd9f14da90dc1a780d9d37fd3a692 "/entrypoint.sh" 3 months ago Exited (0) 3 months ago k8s_contrail-vrouter-init-kernel_contrail-vrouter-agent-kernel-f92x5_contrail_722cdf8d-9138-11e8-976a-525400db35a1_0 df5e0ff4cb9b opencontrailnightly/contrail-node-init@sha256:e9b8dda63953e94e2a51fe058a9fd0d508c257132ba4fa6737b72532a6898d4e "/entrypoint.sh" 3 months ago Exited (0) 3 months ago k8s_contrail-node-init_contrail-vrouter-agent-kernel-f92x5_contrail_722cdf8d-9138-11e8-976a-525400db35a1_0 b6b250499f6c quay.io/stackanetes/kubernetes-entrypoint@sha256:cd8758c539501cd3d4c2b3029d2e774ce1f2260584c0c8d3d8d8c473ba4285bb "kubernetes-entryp..." 3 months ago Exited (0) 3 months ago k8s_init_contrail-vrouter-agent-kernel-f92x5_contrail_722cdf8d-9138-11e8-976a-525400db35a1_0 72fddded7461 gcr.io/google_containers/pause-amd64:3.0 "/pause" 3 months ago Up 3 months k8s_POD_contrail-vrouter-agent-kernel-f92x5_contrail_722cdf8d-9138-11e8-976a-525400db35a1_0 root@ubuntu1604:~# docker exec -it d348c988cdce bash (vrouter-agent)[root@ubuntu1604 /]$ ps -efw UID PID PPID C STIME TTY TIME CMD root 1 0 0 Jul27 ? 00:00:00 /bin/bash /entrypoint.sh /usr/bin/contrail-vrouter-agent root 166 1 5 Jul27 ? 5-00:53:55 /usr/bin/contrail-vrouter-agent root 636 0 4 02:43 ? 00:00:00 bash root 657 636 0 02:43 ? 00:00:00 ps -efw (vrouter-agent)[root@ubuntu1604 /]$ root@ubuntu1604:~# docker ps|grep vrouter d348c988cdce opencontrailnightly/contrail-vrouter-agent@sha256:ede65841bf277479b982310aa6423e9a987d7a1e001e97ea753fb549e5597ce4 "/entrypoint.sh /u..." 5 weeks ago Up 5 weeks k8s_contrail-vrouter-agent_contrail-vrouter-agent-kernel-f92x5_contrail_722cdf8d-9138-11e8-976a-525400db35a1_1 adf22040454d opencontrailnightly/contrail-nodemgr@sha256:d09d687e0d3b91b53679ebd20441414eb3ac07b0555a0036939f60153d7cb2ba "/entrypoint.sh /b..." 5 weeks ago Up 5 weeks k8s_contrail-vrouter-nodemgr_contrail-vrouter-agent-kernel-f92x5_contrail_722cdf8d-9138-11e8-976a-525400db35a1_0 72fddded7461 gcr.io/google_containers/pause-amd64:3.0 "/pause" 5 weeks ago Up 5 weeks k8s_POD_contrail-vrouter-agent-kernel-f92x5_contrail_722cdf8d-9138-11e8-976a-525400db35a1_0
root@ubuntu1604:~# docker logs --details d348c988cdce INFO: agent started in kernel mode INFO: vhost0 is already up Device "crypt0" does not exist. Successfully added ipvlan interface crypt0 Device "decrypt0" does not exist. Successfully added tunnel interface decrypt0 and the required iptables rules INFO: Physical interface: ens4, mac=52:54:00:4b:b8:76, pci=0000:00:04.0 INFO: vhost0 cidr 10.168.6.9/24, gateway 10.168.6.1 INFO: Preparing /etc/contrail/contrail-vrouter-agent.conf INFO: /etc/contrail/contrail-vrouter-agent.conf [CONTROL-NODE] servers=10.168.6.9:5269 <SNIP> root@ubuntu1604:~# docker logs --tail 10 d348c988cdce [CRYPT] crypt_interface=crypt0 [SESSION] slo_destination = collector sample_destination = collector INFO: Preparing /etc/contrail/contrail-lbaas-auth.conf Successfully added tunnel interface decrypt0 to vrouter root@ubuntu1604:~# root@ubuntu1604:~# docker exec -it d348c988cdce bash (vrouter-agent)[root@ubuntu1604 /]$ (vrouter-agent)[root@ubuntu1604 /]$ (vrouter-agent)[root@ubuntu1604 /]$ (vrouter-agent)[root@ubuntu1604 /]$ pwd root@ubuntu1604 /]$ tailf /var/log/contrail/contrail-vrouter-agent.log 2018-07-27 Fri 01:15:01:401.876 UTC ubuntu1604 [Thread 139678473840384, Pid 166]: SANDESH: Send FAILED: 1532654101401758 [SYS_INFO]: XmppConnectionLog: connection= [ ip_address = 10.168.6.9 state = Idle next_state = Active event = Start ] file = controller/src/xmpp/xmpp_state_machine.cc line = 1706