Kubernetes Logs 如何获取kube-system pod的日志

Kubernetes Logs 如何获取kube-system pod的日志

 

你如何从kube-system pod获取日志?运行kubectl log pod_name不起作用:

[root@k8s-master ~]# kubectl logs etcd-k8s-master 
Error from server (NotFound): pods "etcd-k8s-master" not found

查看集群中的所有命名空间:

Kubernetes Logs 如何获取kube-system pod的日志
[root@k8s-master ~]# kubectl get pods --all-namespaces
NAMESPACE     NAME                                 READY   STATUS    RESTARTS   AGE
default       nginx-demo-v1-94kqx                  1/1     Running   0          23m
default       nginx-demo-v1-t88mj                  1/1     Running   0          23m
kube-system   coredns-9d85f5447-jb8l2              1/1     Running   0          6d7h
kube-system   coredns-9d85f5447-zx2j5              1/1     Running   0          6d7h
kube-system   etcd-k8s-master                      1/1     Running   0          6d7h
kube-system   kube-apiserver-k8s-master            1/1     Running   0          6d7h
kube-system   kube-controller-manager-k8s-master   1/1     Running   1          6d7h
kube-system   kube-flannel-ds-amd64-2plp7          1/1     Running   0          6d4h
kube-system   kube-flannel-ds-amd64-cnlbh          1/1     Running   0          6d4h
kube-system   kube-flannel-ds-amd64-zr88r          1/1     Running   0          6d4h
kube-system   kube-proxy-44fpd                     1/1     Running   0          6d6h
kube-system   kube-proxy-5lrvp                     1/1     Running   0          6d7h
kube-system   kube-proxy-c64px                     1/1     Running   0          6d6h
kube-system   kube-scheduler-k8s-master            1/1     Running   1          6d7h
Kubernetes Logs 如何获取kube-system pod的日志

出处:https://www.cnblogs.com/liucx/

指定命名空间可以查看kube-system的pod日志

kubectl –namespace kube-system logs kube-apiserver-k8s-master

eg:
kubectl -n kube-system  logs -f  etcd-k8s-master   #-f:动态实时查看日志
kubectl logs -f etcd-k8s-master  -n kube-system 
kubectl -n kube-system  logs -f  --tail 10 etcd-k8s-master #--tail:指定条数

kubectl log <pod-name> -c <container_name> # 若 pod 只有一个容器,可以不加 -c

 

上一篇:kubeadm部署安装k8s集群


下一篇:VScode执行Run Code命令无输出结果且抛出Code is already running!