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 issues
Prerequisites
- A working Kubernetes cluster
- kubectl installed
- Metrics Server installed (for kubectl top)
Exercise 1: Monitoring the Control Plane
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: Monitoring Nodes
Step 1: Node Health
# View the status of all nodes
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'
# Error events
kubectl get events --all-namespaces --field-selector type=Warning
# Events in 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: Troubleshooting
Step 1: Common Issues
# Pods in error
kubectl get pods --all-namespaces --field-selector status.phase!=Running
# Pods restarting
kubectl get pods --all-namespaces | grep -E "Error|CrashLoopBackOff"
# Nodes NotReady
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
- Which components are critical for the cluster's operation?
- How do you detect a problem with a component?
- Which metrics are most important to monitor?
- How would you react if a node becomes NotReady?
Cleanup
No cleanup necessary.
Next Steps
Module 3: Pods and Deployments
Module 2 Quiz: Validate your knowledge
Lab created on: December 2024