当前位置:网站首页>A method for quickly viewing pod logs under frequent tests (grep awk xargs kuberctl)

A method for quickly viewing pod logs under frequent tests (grep awk xargs kuberctl)

2022-07-07 08:27:00 Code two brother

stay k8s During frequent application software testing , You need to check the log frequently

here , Need frequent access pod The name of ,

so much trouble , How to quickly view logs ?

Problem description

How to quickly view flannel Related one pod The Journal ?
 Insert picture description here

How to quickly view logs 1、 View directly from the command line

adopt grep 、awk、xargs combination obtain Appoint pod The name of , Check the log

 Insert picture description here

Refer to the order , as follows

 kubectl get pod -A | grep "kube-flannel-ds" | awk '{print $1" "$2}' | head -1 |xargs kubectl logs -f -n

head -1, It means to obtain the second 1 Row content

xargs Used to get data

How to quickly view logs 2、Makefile The way

Put the above command , Put it in Makefile in
as follows
file Makefile The content of :

log:
	 kubectl get pod -A | grep "kube-flannel-ds" | awk '{print $$1" "$$2}' | head -1 |xargs kubectl logs -f -n

 Insert picture description here

stay Makefile Under the path where the file exists ,
perform

make log 

It's equivalent to checking the log

How to quickly view logs 3、 Script mode

Create a script to view logs , as follows

vim getlog.sh

#!/bin/sh
 kubectl get pod -A | grep "kube-flannel-ds" | awk '{print $1" "$2}' | head -1 |xargs kubectl logs -f -n
chmod +x getlog.sh

When checking the log , direct

./getlog.sh

Entry to published columns , Welcome to subscribe to , Common progress
0  grpc-go、protobuf、multus-cni Technical column The main entrance

1  grpc-go Source code analysis and actual combat    List of articles

2  Protobuf Introduction and actual combat Graphic column    List of articles

3  multus-cni    List of articles (k8s Multi network implementation scheme )

4  grpc、oauth2、openssl、 Two-way authentication 、 One way authentication and other column contents

原网站

版权声明
本文为[Code two brother]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207070525335983.html