AgentSkillsCN

copy-logs-from-k8s

当您需要通过脚本或`copy_logs_from_k8s.py`从Kubernetes集群中下载tikv/tiflash/s3clean日志时,可使用此技能——支持灵活选择特定日志源,并按Pod分别保存日志文件夹。

SKILL.md
--- frontmatter
name: copy-logs-from-k8s
description: Use when you need to download tikv/tiflash/s3clean logs from a Kubernetes cluster using scripts/copy_logs_from_k8s.py, including selecting specific sources and saving per-pod folders.

Copy Logs From K8s

Quick Start

  • Ensure kubectl points to the target cluster.
  • Run from the analysis directory so logs are saved there:
code
python3 .codex/copy-logs-from-k8s/scripts/copy_logs_from_k8s.py
  • Download specific sources:
code
python3 scripts/copy_logs_from_k8s.py --sources tikv
python3 scripts/copy_logs_from_k8s.py --sources tikv,tiflash
  • Or specify sources directly from the analysis directory:
code
python3 .codex/copy-logs-from-k8s/scripts/copy_logs_from_k8s.py --sources tiflash

Outputs

  • Logs are saved under ./<pod-name>/... in the current working directory.
  • tikv: /var/lib/tikv/log
  • tiflash: /data0/logs (uses container serverlog)
  • s3clean: /tmp/s3clean.log -> ./<pod>/s3clean.log

Notes

  • tiflash logs use kubectl exec ... cat because filenames can include : which breaks kubectl cp.
  • Large log sets can take time to copy; re-run safely if interrupted.

Extend To Other Pods

  • Edit scripts/copy_logs_from_k8s.py.
  • Add the new source name to AVAILABLE_SOURCES.
  • Add a LogSource(...) entry in sources within main():
    • Set pod_predicate to match pod names.
    • Use log_dir to copy a directory or single_file for one file.
    • Set container if the pod requires a specific container.
    • Set use_exec_copy=True if kubectl cp fails or filenames include :.