How to view the startup logs using kubectl?
To view the startup logs of Pods in Kubernetes, you can use the following command:
- Use the command “kubectl get pods” to obtain the names of Pods.
- Show me the list of pods.
- View the startup logs of a Pod using the kubectl logs command.
- Display the logs of the pod named
using kubectl command.
By default, the ‘kubectl logs’ command will display the latest logs of a Pod. If a Pod has multiple containers, you can specify the container name using the ‘-c’ option to view the logs of a specific container.
kubectl logs <pod名称> -c <容器名称>
If there are multiple replicas of Pod, you can use the -f option to track log updates in real-time.
kubectl logs -f <pod名称>
You can also use the –since option to view logs within a specific time range. For example, to view logs from the past 1 hour:
kubectl logs --since=1h <pod名称>
Please refer to the official documentation of kubectl logs for more options and usages.