如何查看 Pod 日志:必须为 pod 指定容器名称...选择其中一项:[wait main]

How to see Pod logs: a container name must be specified for pod... choose one of: [wait main]

我正在 运行 运行 Argo 工作流并在 pod 的日志中收到以下错误:

error: a container name must be specified for pod <name>, choose one of: [wait main]

这个错误只在某些时候发生,并且只发生在我的一些模板中,但当它发生时,它是工作流程中 运行 后面的模板(即不是第一个模板 运行).我还不能确定 运行 成功的参数,所以我很乐意提供调试提示。我在下面粘贴了描述的输出。

根据搜索,我认为解决方案很简单,就是我需要在某处附加“-c main”,但我不知道在哪里,也无法在 Argo 文档中找到信息。

描述:

Name:         message-passing-1-q8jgn-607612432
Namespace:    argo
Priority:     0
Node:         REDACTED
Start Time:   Wed, 17 Mar 2021 17:16:37 +0000
Labels:       workflows.argoproj.io/completed=false
              workflows.argoproj.io/workflow=message-passing-1-q8jgn
Annotations:  cni.projectcalico.org/podIP: 192.168.40.140/32
              cni.projectcalico.org/podIPs: 192.168.40.140/32
              workflows.argoproj.io/node-name: message-passing-1-q8jgn.e
              workflows.argoproj.io/outputs: {"exitCode":"6"}
              workflows.argoproj.io/template:
                {"name":"egress","arguments":{},"inputs":{...
Status:       Failed
IP:           192.168.40.140
IPs:
  IP:           192.168.40.140
Controlled By:  Workflow/message-passing-1-q8jgn
Containers:
  wait:
    Container ID:  docker://26d6c30440777add2af7ef3a55474d9ff36b8c562d7aecfb911ce62911e5fda3
    Image:         argoproj/argoexec:v2.12.10
    Image ID:      docker-pullable://argoproj/argoexec@sha256:6edb85a84d3e54881404d1113256a70fcc456ad49c6d168ab9dfc35e4d316a60
    Port:          <none>
    Host Port:     <none>
    Command:
      argoexec
      wait
    State:          Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Wed, 17 Mar 2021 17:16:43 +0000
      Finished:     Wed, 17 Mar 2021 17:17:03 +0000
    Ready:          False
    Restart Count:  0
    Environment:
      ARGO_POD_NAME:  message-passing-1-q8jgn-607612432 (v1:metadata.name)
    Mounts:
      /argo/podmetadata from podmetadata (rw)
      /mainctrfs/mnt/logs from log-p1-vol (rw)
      /mainctrfs/mnt/processed from processed-p1-vol (rw)
      /var/run/docker.sock from docker-sock (ro)
      /var/run/secrets/kubernetes.io/serviceaccount from argo-token-v2w56 (ro)
  main:
    Container ID:  docker://67e6d6d3717ab1080f14cac6655c90d990f95525edba639a2d2c7b3170a7576e
    Image:         REDACTED
    Image ID:      REDACTED
    Port:          <none>
    Host Port:     <none>
    Command:
      /bin/bash
      -c
    Args:
    State:          Terminated
      Reason:       Error
      Exit Code:    6
      Started:      Wed, 17 Mar 2021 17:16:43 +0000
      Finished:     Wed, 17 Mar 2021 17:17:03 +0000
    Ready:          False
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /mnt/logs/ from log-p1-vol (rw)
      /mnt/processed/ from processed-p1-vol (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from argo-token-v2w56 (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  podmetadata:
    Type:  DownwardAPI (a volume populated by information about the pod)
    Items:
      metadata.annotations -> annotations
  docker-sock:
    Type:          HostPath (bare host directory volume)
    Path:          /var/run/docker.sock
    HostPathType:  Socket
  processed-p1-vol:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  message-passing-1-q8jgn-processed-p1-vol
    ReadOnly:   false
  log-p1-vol:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  message-passing-1-q8jgn-log-p1-vol
    ReadOnly:   false
  argo-token-v2w56:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  argo-token-v2w56
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                 node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type    Reason     Age    From               Message
  ----    ------     ----   ----               -------
  Normal  Scheduled  7m35s  default-scheduler  Successfully assigned argo/message-passing-1-q8jgn-607612432 to ack1
  Normal  Pulled     7m31s  kubelet            Container image "argoproj/argoexec:v2.12.10" already present on machine
  Normal  Created    7m31s  kubelet            Created container wait
  Normal  Started    7m30s  kubelet            Started container wait
  Normal  Pulled     7m30s  kubelet            Container image already present on machine
  Normal  Created    7m30s  kubelet            Created container main
  Normal  Started    7m30s  kubelet            Started container main

当您尝试查看具有多个容器的 pod 的日志但未指定要查看日志的容器时,就会发生这种情况。查看日志的典型命令:

kubectl logs <podname>

但是您的 Pod 有两个容器,一个名为“wait”,一个名为“main”。您可以从名为“main”的容器中查看日志:

kubectl logs <podname> -c main

或者您可以通过

查看所有容器的日志
kubectl logs <podname> --all-containers