Now that we have a good number of longer exercises, it makes sense to rename the shorter demos/labs into 'labs' to avoid confusion between the two.
3.5 KiB
Events
-
Kubernetes has an internal structured log of events
-
These events are ordinary resources:
-
we can view them with
kubectl get events -
they can be viewed and created through the Kubernetes API
-
they are stored in Kubernetes default database (e.g. etcd)
-
-
Most components will generate events to let us know what's going on
-
Events can be related to other resources
Reading events
-
kubectl get events(orkubectl get ev) -
Can use
--watch⚠️ Looks like
tail -f, but events aren't necessarily sorted! -
Can use
--all-namespaces -
Cluster events (e.g. related to nodes) are in the
defaultnamespace -
Viewing all "non-normal" events:
kubectl get ev -A --field-selector=type!=Normal(as of Kubernetes 1.19,
typecan be eitherNormalorWarning)
Reading events (take 2)
- When we use
kubectl describeon an object,kubectlretrieves the associated events
.lab[
- See the API requests happening when we use
kubectl describe:kubectl describe service kubernetes --namespace=default -v6 >/dev/null
]
Generating events
-
This is rarely (if ever) done manually
(i.e. by crafting some YAML)
-
But controllers (e.g. operators) need this!
-
It's not mandatory, but it helps with operability
(e.g. when we
kubectl describea CRD, we will see associated events)
⚠️ Work in progress
-
"Events" can be :
-
"old-style" events (in core API group, aka
v1) -
"new-style" events (in API group
events.k8s.io)
-
-
See KEP 383 in particular this comparison between old and new APIs
Experimenting with events
- Let's create an event related to a Node, based on @@LINK[k8s/event-node.yaml]
.lab[
-
Edit
k8s/event-node.yaml -
Update the
nameanduidof theinvolvedObject -
Create the event with
kubectl create -f -
Look at the Node with
kubectl describe
]
Experimenting with events
- Let's create an event related to a Pod, based on @@LINK[k8s/event-pod.yaml]
.lab[
-
Create a pod
-
Edit
k8s/event-pod.yaml -
Edit the
involvedObjectsection (don't forget theuid) -
Create the event with
kubectl create -f -
Look at the Pod with
kubectl describe
]
Generating events in practice
-
In Go, use an
EventRecorderprovided by thekubernetes/client-golibrary -
It will take care of formatting / aggregating events
-
To get an idea of what to put in the
reasonfield, check kubelet events
Cluster operator perspective
-
Events are kept 1 hour by default
-
This can be changed with the
--event-ttlflag on the API server -
On very busy clusters, events can be kept on a separate etcd cluster
-
This is done with the
--etcd-servers-overridesflag on the API server -
Example:
--etcd-servers-overrides=/events#http://127.0.0.1:12379
???
:EN:- Consuming and generating cluster events :FR:- Suivre l'activité du cluster avec les events