Comprender el servicio kube-state-metrics
kube-state-metrics es compatible como una característica solo beta.
kube-state-metrics es un servicio de monitoreo de métricas de terceros que genera métricas basadas en el estado actual de los clústeres de Kubernetes. Puede usar kube-state-metrics para monitorear el estado del clúster y los servicios de Kubernetes. El servicio kube-state-metrics es compatible como una característica solo beta. kube-state-metrics se ejecuta como un servicio de clúster y se instala automáticamente al instalar Paragon Automation. Una vez instalado este servicio, puede habilitar este servicio para generar, monitorear y exponer métricas de varios objetos dentro de un clúster de Kubernetes.
El servicio kube-state-metrics proporciona métricas sobre pods, DaemonSets, despliegues, volumen persistente, puntos finales, entrada, trabajo, arrendamiento y objetos configmap que forman parte de un clúster de Kubernetes.
Lista de métricas expuestas
La siguiente es la lista de métricas que se exponen:
- Pods que se ejecutan en un espacio de nombres
- Pods disponibles
- Información sobre implementaciones exitosas o fallidas
- Estado de los volúmenes persistentes
- Información sobre trabajos en ejecución, exitosos y fallidos
- Pods que están en estado de error
- Salud de la implementación y DaemonSets
- Estado y condición de los nodos de Kubernetes
Habilitar kube-state-metrics
Puede realizar la habilitación kube-state-metrics
desde la CLI y desde la interfaz de usuario de Paragon Automation.
La siguiente es una descripción general de los pasos para habilitar kube-state-metrics desde la interfaz de usuario:
-
Cree un dispositivo no administrado.
El dispositivo no administrado representa el clúster. El nombre de host del dispositivo debe ser la IP del servicio kube-state-metrics. Por ejemplo,
kube-state-metrics.healthbot.svc.cluster.local
. -
Agregar el dispositivo a un grupo de dispositivos.
-
Crear reglas.
-
Aplicar playbooks.
Ejemplo de reglas y manuales
check-daemonset-status.rule
healthbot { topic kube-metrics { rule check-daemonset-status { keys [ daemonset namespace ]; synopsis ""; description "Checks daemon set unavailable status"; sensor daemonset-status { description "Checks daemon set unavailable status"; server-monitoring { sensor-name /kube/daemonset; frequency 60s; } } field daemonset { sensor daemonset-status { path daemonset; } type string; description "Checks status for demonset key"; } field daemonset_status { sensor daemonset-status { path /kube/daemonset/status/number/unavailable; } type float; description "Field to check condition"; } field namespace { sensor daemonset-status { path namespace; } type string; description "Checks status for namespace key"; } trigger daemonset-status { frequency 1offset; term available { when { equal-to "$daemonset_status" 0; } then { status { color green; message "Unavailable demons set is 0 for $namespace $daemonset"; } } } term notavailable { then { status { color red; message "Unavailable demons set is not 0 for $namespace $daemonset"; } } } } } } }
check-deployment-status-condition.rule
healthbot { topic kube-metrics { rule check-deployment-status-condition { keys [ condition deployment namespace ]; synopsis ""; description "Checks kube metrics deployment status condition"; sensor deployment-status { description "Checks kube metrics deployment status condition"; server-monitoring { sensor-name /kube/deployment; frequency 60s; } } field condition { sensor deployment-status { path condition; } type string; description "Deployment condition"; } field deployment { sensor deployment-status { path deployment; } type string; description "Deployment pod name"; } field namespace { sensor deployment-status { path namespace; } type string; description "Deployment namespace"; } field status { sensor deployment-status { path status; } type string; description "Checks for true or false condition"; } trigger deployment-status { frequency 1offset; term available { when { matches-with "$status" true; } then { status { color green; message "Deployment status for $deployment is $status"; } } } term notavailable { then { status { color red; message "Deployment status for $deployment is $status"; } } } } } } }
check-deployment-status-replicas.rule
healthbot { topic kube-metrics { rule check-deployment-status-replicas { keys [ deployment namespace ]; synopsis ""; description "Checks kube metrics deployment replica status"; sensor deployment-status { description "Checks kube metrics deployment replica status"; server-monitoring { sensor-name /kube/deployment; frequency 60s; } } field deployment { sensor deployment-status { path deployment; } type string; description "Deployment pod name"; } field deployment_status { sensor deployment-status { path /kube/deployment/status/replicas; } type float; description "Field to check 0 or other values"; } field namespace { sensor deployment-status { path namespace; } type string; description "Namespace key"; } trigger deployment-status { frequency 1offset; term available { when { not-equal-to "$deployment_status" 0; } then { status { color green; message "Deployment status for replicaset is $deployment_status for $namespace $deployment"; } } } term notavailable { then { status { color red; message "Deployment status for replicaset is $deployment_status for $namespace $deployment"; } } } } } } }
check-node-status.rule
healthbot { topic kube-metrics { rule check-node-status { keys [ condition node ]; synopsis ""; description "Checks node status"; sensor node-status { description "Checks node status"; server-monitoring { sensor-name /kube/node; frequency 60s; } } field condition { sensor node-status { path condition; } type string; description "Node condition"; } field node { sensor node-status { path node; } type string; description "Node name"; } field node_status { constant { value "{{value}}"; } type integer; description "Field to check condition"; } field status { sensor node-status { path status; } type string; description "Status of the node"; } trigger node-status { frequency 1offset; term available { when { matches-with "$status" false { ignore-case; } } then { status { color green; message "$condition for $node is $status"; } } } term notavailable { then { status { color red; message "$condition for $node is $status."; } } } } variable value { value 0; description "Variable to match true(0) condition."; type int; } } } }
check-pod-container-restarts.rule
healthbot { topic kube-metrics { rule check-pod-container-restarts { keys [ container namespace pod uid ]; synopsis ""; description "Checks pod container status restarts"; sensor pod-init-container-status { description "Checks pod container status restarts"; server-monitoring { sensor-name /kube/pod/container; frequency 60s; } } field container { sensor pod-init-container-status { path container; } type string; description "container name"; } field namespace { sensor pod-init-container-status { path namespace; } type string; description "namespace of the pod"; } field pod { sensor pod-init-container-status { path pod; } type string; description "pod name"; } field restart-value { sensor pod-init-container-status { path /kube/pod/container/status/restarts/total; } type integer; description "restart status value"; } field uid { sensor pod-init-container-status { path uid; } type string; description "Id "; } trigger restart-total-status { frequency 1offset; term less-than-ten { when { less-than-or-equal-to "$restart-value" 10; } then { status { color green; message "$namespace pod $pod container $container restart total is $restart-value "; } } } term between-ten-and-twenty { when { range "$restart-value" { min 10; max 20; } } then { status { color yellow; message "$namespace pod $pod container $container restart total is $restart-value "; } } } term more-than-twenty { then { status { color red; message "$namespace pod $pod container $container restart total is $restart-value"; } } } } } } }
check-pod-init-container-status.rule
healthbot { topic kube-metrics { rule check-pod-init-container-status { keys [ container namespace pod uid ]; synopsis ""; description "Checks pod init container status waiting"; sensor pod-init-container-status { description "Checks pod init container status waiting"; server-monitoring { sensor-name /kube/pod/init/container; frequency 60s; } } field container { sensor pod-init-container-status { path container; } type string; description "container name"; } field namespace { sensor pod-init-container-status { path namespace; } type string; description "namespace of the pod"; } field pod { sensor pod-init-container-status { path pod; } type string; description "pod name"; } field status { sensor pod-init-container-status { path /kube/pod/init/container/status/waiting; } type integer; description "Statius value (0/1)"; } field uid { sensor pod-init-container-status { path uid; } type string; description "Id "; } trigger waiting-status { frequency 1offset; term matches-zero { when { equal-to "$status" 0 { time-range 10offset; } } then { status { color green; message "$namespace $pod $container status is $status"; } } } term is-not-zero { then { status { color red; message "$namespace $pod $container status is $status"; } } } } } } }
kube-metrics.playbook
healthbot { playbook kube-metrics { rules [ kube-metrics/check-daemonset-status kube-metrics/check-deployment-status-replicas kube-metrics/check-node-status kube-metrics/check-pod-container-restarts kube-metrics/check-pod-init-container-status kube-metrics/check-deployment-status-condition ]; description "Rules to check for kube-metrics "; synopsis "Rules to check for kube-metrics "; } }