Skip to main content

Lab 2.3 - Monitoring System Components

Objectives

By the end of this lab, you will be able to:

  • Monitor Control Plane components
  • Monitor Worker Nodes
  • Analyze system metrics
  • Identify potential problems

Prerequisites

  • Working Kubernetes cluster
  • kubectl installed
  • Metrics Server installed (for kubectl top)

Exercise 1: Control Plane Monitoring

Step 1: Component Status

# View component status (deprecated but useful)
kubectl get componentstatuses

# View Control Plane Pods
kubectl get pods -n kube-system

Step 2: Component Logs

# API Server logs
kubectl logs -n kube-system -l component=kube-apiserver --tail=100

# Controller Manager logs
kubectl logs -n kube-system -l component=kube-controller-manager --tail=100

# Scheduler logs
kubectl logs -n kube-system -l component=kube-scheduler --tail=100

Exercise 2: Node Monitoring

Step 1: Node Health

# View all node statuses
kubectl get nodes

# Node details
kubectl describe node <node-name>

# View node conditions
kubectl get node <node-name> -o jsonpath='{.status.conditions}'

Step 2: Node Metrics

# Resource usage
kubectl top nodes

# Resource details
kubectl describe node <node-name> | grep -A 20 "Allocated resources"

Exercise 3: Events and Alerts

Step 1: Recent Events

# All events
kubectl get events --all-namespaces --sort-by='.lastTimestamp'

# Warning events
kubectl get events --all-namespaces --field-selector type=Warning

# Events for a namespace
kubectl get events -n kube-system

Step 2: Component Events

# Events related to a system Pod
kubectl describe pod <pod-name> -n kube-system | grep Events -A 10

Exercise 4: Cluster Health

Step 1: General Check

# Cluster information
kubectl cluster-info

# Version
kubectl version

# Available resources
kubectl api-resources

Step 2: System Namespace

# All resources in kube-system
kubectl get all -n kube-system

# System secrets
kubectl get secrets -n kube-system

# System ConfigMaps
kubectl get configmaps -n kube-system

Exercise 5: Diagnostics

Step 1: Common Problems

# Pods in error state
kubectl get pods --all-namespaces --field-selector status.phase!=Running

# Pods that are restarting
kubectl get pods --all-namespaces | grep -E "Error|CrashLoopBackOff"

# NotReady nodes
kubectl get nodes | grep NotReady

Step 2: Log Analysis

# Logs of a crashing Pod
kubectl logs <pod-name> -n <namespace> --previous

# Logs of all containers
kubectl logs <pod-name> -n <namespace> --all-containers=true

Reflection Questions

  1. Which components are critical for cluster operation?
  2. How do you detect a problem with a component?
  3. Which metrics are the most important to monitor?
  4. How would you react if a node becomes NotReady?

Cleanup

No cleanup needed.


Next Steps

Module 3: Pods and Deployments
Quiz Module 2: Validate your knowledge


Lab created: December 2024