Supervisión de Kubernetes con Prometheus y Thanos

La víspera del inicio del curso profesional "Monitoreo y registro: Zabbix, Prometheus, ELK" , hemos preparado una traducción interesante para usted y también le ofrecemos ver una lección de demostración sobre el tema : "Prometheus como una nueva ronda de sistemas de monitoreo" .


Introducción

¡Felicidades! Consiguió convencer a sus jefes de que migraran aplicaciones a una arquitectura de microservicio utilizando contenedores y Kubernetes .

Estás muy feliz y todo va según lo planeado. Usted crea su primer clúster de Kubernetes (todos los principales proveedores de nube, Azure, AWS y GCP , tienen soluciones simples para aprovisionar Kubernetes administrado o no administrado ), desarrolla su primera aplicación en contenedores e impleméntela en el clúster. Fue fácil, ¿no?

Después de un tiempo, se da cuenta de que las cosas se complican un poco más: necesita implementar varias aplicaciones en un clúster, por lo que necesita un controlador de entrada . A continuación, desea controlar la carga, por lo que comienza a buscar soluciones para eso y, afortunadamente, encuentra Prometheus . ¡Expande, agrega Grafana y listo !

: " Prometheus "? ? ? Prometheus ? ? HA DR? Prometheus

, , .

Kubernetes

Kubernetes.

Clúster de Kubernetes típico
Kubernetes

:

  1. : master- worker-.

  2. Kubernetes.

  3. .

HTTP(s) (REST gRPC), API (Ingress). API :

  1. Kubernetes API Server.

  2. Ingress Controller.

, Azure SQL, Azure Blob .

?

Kubernetes , .

. , , :

  • .

  • (, , , ).

  • (, ..).

  • , .

Kubernetes. Kubernetes :

  • — ready ( ), status, restarts ( ), age ( ).

  • (Deployments) — desired ( ), current ( ), up-to-date ( ), available ( ), age ( ).

  • StatefulSets.

  • CronJobs.

  • ( ).

  • (Health checks).

  • Kubernetes.

  • API-.

  • Etcd.

  • .

.  , . , :

  • HTTP- ( , , . .).

  • (, ).

  • .

, , , . 

Thanos

Thanos — , , Prometheus.

Thanos Prometheus . , global view Prometheus.

Thanos:

  • Sidecar. Prometheus Query Gateway / .

  • Query Gateway. Prometheus API ( Sidecar Store Gateway).

  • Store Gateway. .

  • Compactor. (downsampling) .

  • Receiver. remote-write WAL Prometheus, / .

  • Ruler. recording rules alerting rules Thanos.

.

Thanos

Thanos Sidecar Kubernetes, , Prometheus Grafana.

Prometheus, Prometheus-Operator, Kubernetes, Prometheus.

Prometheus-Operator Helm , , Thanos Sidecar , Kubernetes .

Thanos Sidecar Kubernetes Secret , . 

Microsoft Azure.

account blob-:

az storage account create --name <storage_name> --resource-group <resource_group> --location <location> --sku Standard_LRS --encryption blob

( container) :

az storage container create --account-name <storage_name> --name thanos

:

az storage account keys list -g <resource_group> -n <storage_name>

(thanos-storage-config.yaml):

Kubernetes Secret:

kubectl -n monitoring create secret generic thanos-objstore-config --from-file=thanos.yaml=thanos-storage-config.yaml

prometheus-operator-values.yaml, Prometheus-Operator.

:

helm install --namespace monitoring --name prometheus-operator stable/prometheus-operator -f prometheus-operator-values.yaml

Prometheus Thanos Sidecar, Azure Blob Storage .

Thanos Store Gateway Thanos Sidecar, Ingress. Nginx Ingress Controller, Ingress Controller, gRPC (, Envoy ).

Thanos Store Gateway Thanos Sidecar mutual TLS. .

.pfx-, , openssl:

# public key
openssl pkcs12 -in cert.pfx -nocerts -nodes | sed -ne '/-BEGIN PRIVATE KEY-/,/-END PRIVATE KEY-/p' > cert.key
# private key
openssl pkcs12 -in cert.pfx -clcerts -nokeys | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > cert.cer
# certificate authority (CA)
openssl pkcs12 -in cert.pfx -cacerts -nokeys -chain | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > cacerts.cer

Kubernetes Secrets.

# a secret to be used for TLS termination
kubectl create secret tls -n monitoring thanos-ingress-secret --key ./cert.key --cert ./cert.cer
# a secret to be used for client authenticating using the same CA
kubectl create secret generic -n monitoring thanos-ca-secret --from-file=ca.crt=./cacerts.cer

, , Kubernetes, ,  Thaos SideCar: 

thanos-0.your.domain
thanos-1.your.domain

Ingress ( ):

Thanos Sidecars !

Thanos

Thanos, , , Thanos . , , .

Thanos Helm ( , , PR).

thanos-values.yaml, .

Thanos Store Gateway blob-, .

kubectl -n thanos create secret generic thanos-objstore-config --from-file=thanos.yaml=thanos-storage-config.yaml

, .

helm install --name thanos --namespace thanos ./thanos -f thanos-values.yaml --set-file query.tlsClient.cert=cert.cer --set-file query.tlsClient.key=cert.key --set-file query.tlsClient.ca=cacerts.cer --set-file store.tlsServer.cert=cert.cer --set-file store.tlsServer.key=cert.key --set-file store.tlsServer.ca=cacerts.cer

Thanos Query Gateway Thanos Storage Gateway, .

, , HTTP- Thanos Query Gateway :

kubectl -n thanos port-forward svc/thanos-query-http 8080:10902

http://localhost:8080, Thanos UI!

Grafana

Grafana, Helm .

grafana-values.yaml :

, . ( — ConfigMap).

:

helm install --name grafana --namespace thanos stable/grafana -f grafana-values.yaml

port-forward:

kubectl -n thanos port-forward svc/grafana 8080:80

… ! Prometheus !

Prometheus Thanos, global view , Prometheus .

Cortex — , , Thanos, .


-, - OTUS .




All Articles