DevOps Adventures…Log parser – Downloading Logs
DevOps Adventures...Log parser – Downloading Logs
When we have plan how to download logs, we can move to downloading itself. For such purpose we will need the following:
1. k8s endpoint
2. service account with token
3. cluster role + role binding
4. reqwest library
To download logs (considering we have everything set up) we simply send GET request for specific endpoint:
https://${CLUSTER_IP}/api/v1/namespaces/${NAMESPACE}/pods/{hostname}/log?&tailLines=10&follow×tamps=true
Above URL gives us access to logs which additonally consists timestamp. But before we get there, we need something more:
https://${CLUSTER_IP}/api/v1/namespaces/${NAMESPACE}/pods/
Above URL gives us possibility to list pods for specific namespace. We will need this, since in real life scenario, especially in production environments there are more pods than 1 in specific namespace. So in simple terms we will need construction like this: for each pod in specific namespace, download log with timestamp.
For now, this configuration gives us insight into logs in real time, which are printed into console output.

