When using Kubernetes it's common to have multiple instances of a pod running. Each pod will create a unique log available in the "logs selector" dropdown (see screenshot). I'd like to search for text in only specific logs in the Google Cloud Logging console. For example I'd like to search for text "Something" in all logs whose name contains "my-pod-v1". Is this possible?
1 Answers
With nodes at Kubernetes 1.0 or below, your best option is using Cloud Logging's "Advanced Filters". You can enable the advanced filter option by selectiong the menu dropdown at the end of the search bar and choosing "Convert to advanced filter".
Advanced filters allow you to do substring matching on name of the logs with the :
operator, so you could use an advanced filter query query like structPayload:Something log:kubernetes.my-pod-v1
to select log lines that include the text "Something" from logs whose name starts with "kubernetes.my-pod-v1". Be warned that this query will probably be quite slow, but it should work.
With nodes at Kubernetes 1.1 or above, this sort of query gets significantly easier, because Container Engine logs get their own hierarchy in the dropdown boxes and the log names are the container name rather than the pod name, so all logs from replicas with the same container in them can be trivially grouped together by choosing the appropriate log name.

- 12,633
- 2
- 38
- 55