你如何从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
来源:oschina
链接:https://my.oschina.net/u/4299953/blog/3235414