【问题标题】:Can not get logs of Kubernetes K8S pod (to debug)无法获取 Kubernetes K8S pod 的日志(调试)
【发布时间】:2021-11-30 17:47:49
【问题描述】:

我有 1 个主节点和 2 个节点正在运行,并且要调试 kube-proxy。

kube-m1:/$ kubectl get pod -n kube-system kube-proxy-tmt58
NAME               READY   STATUS    RESTARTS   AGE
kube-proxy-tmt58   1/1     Running   6          439d

如何指定命名空间以获取 kubectl logs 来调试 pod?

kube-m1:/$ kubectl logs kube-proxy-tmt58
Error from server (NotFound): pods "kube-proxy-tmt58" not found

我是 kubernetes 的新手,因此,如果能获得一些关于 pod 和节点调试的良好且有效的指南或材料,也会非常有帮助:)

非常感谢。

【问题讨论】:

    标签: kubernetes nodes kube-proxy


    【解决方案1】:

    就像你获取一个 pod 一样,指定一个命名空间你可以传递 -n | --namespace 标志,所以你的命令看起来像

    kubectl logs kube-proxy-tmt58 -n kube-system
    

    【讨论】:

      【解决方案2】:

      除了@jabbson 的回答我只想提一下并推荐你保存到书签中kubectl Cheat Sheet。这个页面有大量的 kubectl 使用示例。对深入kubernetes世界有很大帮助。

      # Get commands with basic output
      kubectl get services                          # List all services in the namespace
      kubectl get pods --all-namespaces             # List all pods in all namespaces
      kubectl get pods -o wide                      # List all pods in the current namespace, with more details
      kubectl get deployment my-dep                 # List a particular deployment
      kubectl get pods                              # List all pods in the namespace
      kubectl get pod my-pod -o yaml                # Get a pod's YAML
      
      # Describe commands with verbose output
      kubectl describe nodes my-node
      kubectl describe pods my-pod
      
      # Get all worker nodes (use a selector to exclude results that have a label
      # named 'node-role.kubernetes.io/master')
      kubectl get node --selector='!node-role.kubernetes.io/master'
      
      # Get all running pods in the namespace
      kubectl get pods --field-selector=status.phase=Running
      
      # Get ExternalIPs of all nodes
      kubectl get nodes -o jsonpath='{.items[*].status.addresses[?(@.type=="ExternalIP")].address}'
      
      # Logs
      kubectl logs my-pod                                 # dump pod logs (stdout)
      kubectl logs -l name=myLabel                        # dump pod logs, with label name=myLabel (stdout)
      kubectl logs my-pod --previous                      # dump pod logs (stdout) for a previous instantiation of a container
      kubectl logs my-pod -c my-container                 # dump pod container logs (stdout, multi-container case)
      kubectl logs -l name=myLabel -c my-container        # dump pod logs, with label name=myLabel (stdout)
      kubectl logs my-pod -c my-container --previous      # dump pod container logs (stdout, multi-container case) for a previous instantiation of a container
      kubectl logs -f my-pod                              # stream pod logs (stdout)
      kubectl logs -f my-pod -c my-container              # stream pod container logs (stdout, multi-container case)
      kubectl logs -f -l name=myLabel --all-containers    # stream all pods logs with label name=myLabel (stdout)
      

      【讨论】:

        猜你喜欢
        • 2021-06-13
        • 1970-01-01
        • 2017-12-24
        • 2019-01-20
        • 2020-09-06
        • 2021-01-15
        • 2019-07-21
        • 2020-01-09
        • 1970-01-01
        相关资源
        最近更新 更多