除了 Kubernetes 中的 pod 之外,我还可以从其他资源获取事件吗?

Can I get events from other resources in addition to the pod in Kubernetes?

当运行此命令用于 Pod 以外的资源(deployment、ReplicaSet ...)时

$ kubectl describe deployment xxx-deployment 

----           ------  ------

Events:          <none>

我已经部署了几个资源,但是除了Pod我还没有看到事件。

如果事件发生在其他资源中,会发生什么类型的事件?

有什么资料可以推荐一下吗?

您还可以使用 --labels 标签过滤以描述所有资源

是的,部署确实有事件。但请记住,活动仅提供大约 1 小时。

很好地解释了 Kubernetes 中的事件,您可以在 Types of Kubernetes Events 文章中找到。作者还提到了事件类型。

Kubernetes events are a resource type in Kubernetes that are automatically created when other resources have state changes, errors, or other messages that should be broadcast to the system. While there is not a lot of documentation available for events, they are an invaluable resource when debugging issues in your Kubernetes cluster.

您不仅可以描述 poddeploymentreplicaset,还可以描述 几乎所有 kubernetes 中的资源。

示例:

  • kubectl describe job pi -n test
Events:
  Type    Reason            Age   From            Message
  ----    ------            ----  ----            -------
  Normal  SuccessfulCreate  12s   job-controller  Created pod: pi-5rgbz
  • kubectl describe node ubuntu
Events:
  Type     Reason                   Age                 From                   Message
  ----     ------                   ----                ----                   -------
  Warning  MissingClusterDNS        22h (x98 over 23h)  kubelet, ubuntu-18     kubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. Falling back to "Default" policy.
  Normal   Starting                 22h                 kubelet, ubuntu-18     Starting kubelet.
  Warning  InvalidDiskCapacity      22h                 kubelet, ubuntu-18     invalid capacity 0 on image filesystem
  Normal   NodeHasSufficientMemory  22h                 kubelet, ubuntu-18     Node ubuntu-18 status is now: NodeHasSufficientMemory
  Normal   NodeHasSufficientPID     22h    

列出您可以使用的所有资源事件 $ kubectl get events --all-namespaces

$ kubectl get events --all-namespaces
NAMESPACE     LAST SEEN   TYPE      REASON                    OBJECT                                                           MESSAGE
default       50m         Normal    Starting                  node/gke-cluster-1-default-pool-XXXXXXXXXXXXX                    Starting kubelet.
default       50m         Normal    NodeHasSufficientMemory   node/gke-cluster-1-default-pool-XXXXXXXXXXXXX                    Node gke-cluster-1-default-pool-XXXXXXXXXXXXX status is now: NodeHasSufficientMemory
default       2m47s       Normal    SuccessfulCreate          job/pi                                                           Created pod: pi-5rgbz
kube-system   50m         Normal    ScalingReplicaSet         deployment/fluentd-gcp-scaler                                    Scaled up replica set fluentd-gcp-scaler-6855f55bcc to 1

在您的资源类型的对象列中。

如果您想了解更详细的信息,可以使用 -o wide 标志 - $ kubectl get events --all-namespaces -o wide

$ kubectl get events -o wide
LAST SEEN   TYPE      REASON                    OBJECT                                   SUBOBJECT                      SOURCE                     MESSAGE                                      
                                                                                                                                                                    FIRST SEEN   COUNT   NAME
20m         Normal    Scheduled                 pod/hello-world-86d6c6f84d-8qz9d                                        default-scheduler          Successfully assigned default/hello-world-86d
6c6f84d-8qz9d to ubuntu-18  

可能是根本原因。

一开始我无法在没有任何事件的情况下创建部署我猜你已经设置了 --event-ttl,这在 Kube-apiserver docs.

中有描述

--event-ttl duration Default: 1h0m0s

Amount of time to retain events.

Github thread中也提到了。

简而言之,如果您设置了此标志,所有事件将在 1 小时后消失。

要检查您是否在 kube-apiserver 中设置了此标志,您可以检查

如果这对您没有帮助,请使用您的配置 YAML、您使用的 K8s 版本、重现步骤等信息编辑您的问题。