[root@k8s-master01 k8s-leaderelection]# kubectl get events -A
NAMESPACE LAST SEEN TYPE REASON OBJECT MESSAGE
injection 3m21s Warning FailedMount pod/alpine01 MountVolume.SetUp failed for volume "nginx-conf": configmap "nginx-configmap" not found
nginx-injection 32m Normal Pulled pod/test-alpine-inject-01 Container image "alpine" already present on machine
nginx-injection 32m Normal Created pod/test-alpine-inject-01 Created container alpine
nginx-injection 32m Normal Started pod/test-alpine-inject-01 Started container alpine
nginx-injection 27m Normal Pulled pod/test-alpine-inject-02 Container image "alpine" already present on machine
nginx-injection 27m Normal Created pod/test-alpine-inject-02 Created container alpine
nginx-injection 27m Normal Started pod/test-alpine-inject-02 Started container alpine
describe 资源获取
比如创建pod时故意将容器的image 仓库名字写错
apiVersion: v1
kind: Pod
metadata:name: nginx-pod-test
spec:containers:-name: nginx
image: nginxa:1.8
创建之后就可以describe 这个pod获取events,可以看到拉取镜像失败的events
[root@k8s-master01 app]# kubectl describe pod nginx-pod-test
Name: nginx-pod-test
Namespace: default
Priority: 0
Node: k8s-node01/172.20.70.215
Start Time: Wed, 15 Sep 202119:13:20 +0800
Labels: <none>
Annotations: cni.projectcalico.org/podIP: 10.100.85.220/32
cni.projectcalico.org/podIPs: 10.100.85.220/32
Status: Pending
IP: 10.100.85.220
IPs:
IP: 10.100.85.220
Containers:
nginx:
Container ID:
Image: nginxa:1.8
Image ID:
Port: <none>
Host Port: <none>
State: Waiting
Reason: ImagePullBackOff
Ready: False
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-k46nh (ro)
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
Volumes:
default-token-k46nh:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-k46nh
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 2m57s default-scheduler Successfully assigned default/nginx-pod-test to k8s-node01
Normal Pulling 67s (x4 over 2m57s) kubelet Pulling image "nginxa:1.8"
Warning Failed 63s (x4 over 2m49s) kubelet Failed to pull image "nginxa:1.8": rpc error: code = Unknown desc = failed to pull and unpack image "docker.io/library/nginxa:1.8": failed to resolve reference "docker.io/library/nginxa:1.8": pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed
Warning Failed 63s (x4 over 2m49s) kubelet Error: ErrImagePull
Normal BackOff 50s (x6 over 2m49s) kubelet Back-off pulling image "nginxa:1.8"
Warning Failed 39s (x7 over 2m49s) kubelet Error: ImagePullBackOff
// NewEventBroadcasterAdapter creates a wrapper around new and legacy broadcasters to simplify// migration of individual components to the new Event API.funcNewEventBroadcasterAdapter(client clientset.Interface) EventBroadcasterAdapter {
eventClient :=&eventBroadcasterAdapterImpl{
}if_, err := client.Discovery().ServerResourcesForGroupVersion(eventsv1.SchemeGroupVersion.String()); err ==nil{
eventClient.eventsv1Client = client.EventsV1()