我试图将k8s中的pod的日志重定向到其名称的文件中。
kubectl get pods | awk '{print $1}' | tail -2 | xargs -I {} kubectl logs {} > {}
这就是结果。
demo@demo1:~/log$ ls
{}
我需要的是(如果这是吊舱详细信息)
demo@demo1:~/log$ kubectl get pods
NAME READY STATUS RESTARTS AGE
pod1 1/1 Running 0 3d23h
pod2 1/1 Running 0 3d23h
The expected result is
demo@demo1:~/log$ ls
pod1 pod2
文件pod1和pod2将具有各个pod的日志。
Courtesy to this answer