Bird
Raised Fist0
Kubernetesdevops~20 mins

Event inspection for diagnostics in Kubernetes - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Event Inspection Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
What is the output of this command?
You run the command kubectl get events --field-selector involvedObject.kind=Pod,involvedObject.name=myapp-pod. What does this command show?
Kubernetes
kubectl get events --field-selector involvedObject.kind=Pod,involvedObject.name=myapp-pod
AAn error message saying the field-selector is invalid.
BA list of all events in the cluster, including nodes, services, and pods.
CA list of events related only to the Pod named 'myapp-pod', showing recent warnings and normal messages.
DNo output because the command filters out all events.
Attempts:
2 left
💡 Hint
Field selectors filter events by object kind and name.
Troubleshoot
intermediate
1:30remaining
Why does this event inspection command return no events?
You run kubectl get events --namespace=production --field-selector reason=FailedScheduling but get no events. What is the most likely reason?
Kubernetes
kubectl get events --namespace=production --field-selector reason=FailedScheduling
AThere are no scheduling failures in the 'production' namespace currently.
BThe 'reason' field selector is not supported by kubectl.
CYou must add <code>--all-namespaces</code> to see events across namespaces.
DThe command syntax is incorrect; 'reason' should be 'type'.
Attempts:
2 left
💡 Hint
Field selectors only show matching events if they exist.
Configuration
advanced
2:00remaining
How to configure event retention duration in Kubernetes?
You want to increase how long Kubernetes keeps events before deleting them. Which configuration change achieves this?
AChange the <code>kube-controller-manager</code> config to increase event storage size.
BModify the pod spec to include <code>eventRetention: 48h</code> under metadata.
CAdd an annotation <code>event.kubernetes.io/ttl=48h</code> to each event manually.
DSet the <code>--event-ttl</code> flag on the kube-apiserver to a longer duration like '48h'.
Attempts:
2 left
💡 Hint
Event TTL is controlled by the API server flag.
🔀 Workflow
advanced
2:30remaining
What is the correct workflow to diagnose a pod crash using events?
You notice a pod is crashing repeatedly. Which sequence of commands helps diagnose the issue using events?
A1, 4, 3, 2
B4, 1, 2, 3
C4, 2, 1, 3
D2, 4, 1, 3
Attempts:
2 left
💡 Hint
Start by listing pods, then describe, then check events and logs.
Best Practice
expert
3:00remaining
Which practice best improves event inspection for long-term diagnostics?
You want to keep Kubernetes events for weeks to analyze intermittent issues. What is the best approach?
AIntegrate Kubernetes events with an external logging system like Elasticsearch or Loki.
BManually export events daily using <code>kubectl get events</code> and save to files.
CIncrease the <code>--event-ttl</code> flag on kube-apiserver to several weeks.
DAnnotate each event with a timestamp to prevent deletion.
Attempts:
2 left
💡 Hint
Kubernetes events are ephemeral; external storage is recommended.

Practice

(1/5)
1. What is the primary purpose of Kubernetes events when diagnosing cluster issues?
easy
A. To deploy new applications to the cluster
B. To permanently store all logs from containers
C. To configure network policies automatically
D. To show what is happening inside the cluster in real-time

Solution

  1. Step 1: Understand Kubernetes events role

    Kubernetes events provide information about actions and changes happening inside the cluster, like pod starts or errors.
  2. Step 2: Differentiate from other cluster functions

    Events are not for storing logs, configuring policies, or deploying apps; they are for showing cluster activity.
  3. Final Answer:

    To show what is happening inside the cluster in real-time -> Option D
  4. Quick Check:

    Events = cluster activity info [OK]
Hint: Events show cluster actions and changes live [OK]
Common Mistakes:
  • Confusing events with logs storage
  • Thinking events deploy apps
  • Assuming events configure network
2. Which of the following commands correctly lists recent Kubernetes events sorted by timestamp?
easy
A. kubectl get events --sort-by=.metadata.creationTimestamp
B. kubectl describe events --sort=timestamp
C. kubectl events list --order=asc
D. kubectl get pods --events

Solution

  1. Step 1: Identify correct kubectl syntax for events

    The command to list events is 'kubectl get events'. To sort by timestamp, use '--sort-by=.metadata.creationTimestamp'.
  2. Step 2: Check other options for syntax errors

    'kubectl describe events' does not support '--sort', 'kubectl events list' is invalid, and 'kubectl get pods --events' is not a valid flag.
  3. Final Answer:

    kubectl get events --sort-by=.metadata.creationTimestamp -> Option A
  4. Quick Check:

    Correct command = kubectl get events --sort-by=.metadata.creationTimestamp [OK]
Hint: Use --sort-by=.metadata.creationTimestamp with kubectl get events [OK]
Common Mistakes:
  • Using invalid flags like --sort or --order
  • Trying to list events with kubectl describe
  • Confusing pods command with events
3. Given the command kubectl get events --field-selector involvedObject.kind=Pod --sort-by=.lastTimestamp, what is the expected output?
medium
A. A list of all Pods sorted by creation time
B. A list of all events related to Pods sorted by the last event time
C. An error because --field-selector is invalid with events
D. A list of all nodes with their event counts

Solution

  1. Step 1: Understand the command filters and sorting

    The command filters events to only those involving Pods using '--field-selector involvedObject.kind=Pod' and sorts them by '.lastTimestamp'.
  2. Step 2: Interpret the output type

    The output will be events related to Pods, not Pods themselves or nodes, and no syntax error occurs.
  3. Final Answer:

    A list of all events related to Pods sorted by the last event time -> Option B
  4. Quick Check:

    Field selector filters events by Pod, sorted by lastTimestamp [OK]
Hint: Field selector filters events; sort-by orders by timestamp [OK]
Common Mistakes:
  • Thinking it lists Pods instead of events
  • Assuming syntax error with field-selector
  • Confusing nodes with Pods
4. You run kubectl get events --sort-by=.metadata.lastTimestamp but get an error: "error: unknown field selector: .metadata.lastTimestamp". What is the likely cause?
medium
A. Mixing --sort-by with an invalid field selector syntax
B. Trying to sort by a field not supported for sorting events
C. Using --sort-by with an incorrect field path for events
D. Using --sort-by with a field selector syntax instead of sorting

Solution

  1. Step 1: Analyze the error message

    The error says "unknown field selector" which suggests the field path used with --sort-by is incorrect for events.
  2. Step 2: Verify correct field path for sorting events

    The correct field path for sorting events by last occurrence time is '.lastTimestamp' (root level field). '.metadata.lastTimestamp' does not exist, causing the unknown field error.
  3. Step 3: Identify the most accurate cause

    Using --sort-by with an incorrect field path for events correctly states the issue is an incorrect field path for sorting events, causing the error.
  4. Final Answer:

    Using --sort-by with an incorrect field path for events -> Option C
  5. Quick Check:

    Incorrect field path in --sort-by causes error [OK]
Hint: Check field path spelling and validity for --sort-by [OK]
Common Mistakes:
  • Confusing --sort-by with --field-selector
  • Assuming syntax error in command structure
  • Ignoring field path case sensitivity
5. You want to monitor only warning events related to Pods in the default namespace and see the newest events first. Which command achieves this?
hard
A. kubectl get events -n default --field-selector type=Warning,involvedObject.kind=Pod --sort-by=.lastTimestamp
B. kubectl get events -n default --field-selector type=Warning,involvedObject.kind=Pod --sort-by=.metadata.creationTimestamp
C. kubectl get events --field-selector type=Warning,involvedObject.kind=Pod -n default --sort-by=.metadata.lastTimestamp
D. kubectl get pods -n default --filter type=Warning --sort-by=.lastTimestamp

Solution

  1. Step 1: Filter events by type and involved object

    Use '--field-selector type=Warning,involvedObject.kind=Pod' to get warning events related to Pods.
  2. Step 2: Specify namespace and sort order

    Use '-n default' for the default namespace and '--sort-by=.lastTimestamp' to sort newest events first.
  3. Step 3: Evaluate options

    kubectl get events -n default --field-selector type=Warning,involvedObject.kind=Pod --sort-by=.lastTimestamp correctly combines all requirements. kubectl get events --field-selector type=Warning,involvedObject.kind=Pod -n default --sort-by=.metadata.lastTimestamp has wrong sort field, B uses creationTimestamp which sorts oldest first, D is invalid as it targets pods, not events.
  4. Final Answer:

    kubectl get events -n default --field-selector type=Warning,involvedObject.kind=Pod --sort-by=.lastTimestamp -> Option A
  5. Quick Check:

    Filter warnings on Pods, default namespace, sort by lastTimestamp [OK]
Hint: Filter warnings on Pods, sort by lastTimestamp for newest first [OK]
Common Mistakes:
  • Using wrong sort field for newest events
  • Filtering pods instead of events
  • Omitting namespace or using wrong flags