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

|▌冷眼眸甩不掉的悲伤 提交于 2020-04-15 14:59:21

【推荐阅读】微服务还能火多久?>>>

你如何从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

以下是查看所有命名空间的输出:

[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

指定命名空间可以查看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

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!