DEV Community

Mesrar
Mesrar

Posted on

A Comprehensive Guide to Taints, Tolerations, Logging, and Monitoring

Taints (on nodes) and Tolerations (on pods)
Understanding Taints on Nodes
To inspect taints on a specific node, use the following command:

kubectl describe node <node-name> | grep -i "taint"

Enter fullscreen mode Exit fullscreen mode

Tainting a Node
Create a taint on a node with a specific key, value, and effect:

kubectl taint node <node-name> spray=mortein:NoSchedule

Enter fullscreen mode Exit fullscreen mode

spray: Key of the taint.
mortein: Value associated with the key.
NoSchedule: Effect that defines the behavior of pods that do not tolerate this taint.

Tolerations on Pods

When deploying pods, use tolerations to allow them to tolerate specific node taints. In the pod specification, add a tolerations section under spec with properties like key, operator, value, and effect:

#yaml

apiVersion: v1
kind: Pod
metadata:
  name: mypod
spec:
  tolerations:
  - key: "spray"
    operator: "Equal"
    value: "mortein"
    effect: "NoSchedule"
  containers:
  - name: mycontainer
    image: myimage
Enter fullscreen mode Exit fullscreen mode

Removing Taints
To remove a specific taint from a node:

kubectl taint node <node-name> key=value:effect-

Enter fullscreen mode Exit fullscreen mode

For example, to remove all taints with key 'dedicated' from node 'foo':

kubectl taint node foo dedicated-

Enter fullscreen mode Exit fullscreen mode

Logging
Viewing Container Logs
Check the standard output of a container using the logs command:


kubectl logs -f <pod-name> <container-name> # Follow the logs
kubectl logs <pod-name> --previous # Dump pod logs for a 
previous instantiation of a container
Enter fullscreen mode Exit fullscreen mode

Monitoring
Resource Usage Metrics
Get resource usage metrics for nodes and pods:

kubectl top node
kubectl top pod
Enter fullscreen mode Exit fullscreen mode

Identifying CPU-Intensive Pod
To find the pod consuming the most CPU:


kubectl top pod --namespace=default | head -2 | tail -1 | cut -d " " -f1
kubectl top pod --sort-by cpu --no-headers
Enter fullscreen mode Exit fullscreen mode

Empower your Kubernetes journey with insights into taints, tolerations, efficient logging, and real-time monitoring.

Happy Kuberneting!

Top comments (0)