Setting up Kubernetes monitoring with Thanos involves deploying Thanos components alongside Prometheus to achieve high availability and long-term storage of metrics. Here’s a step-by-step guide:
Prerequisites:
- A Kubernetes Cluster: Ensure you have a running Kubernetes cluster.
- kubectl: Make sure you have
kubectlinstalled and configured to interact with your cluster. - Helm: Install Helm, a package manager for Kubernetes, if you haven’t already.
Step 1: Install Prometheus Operator
helm repo add stable https://charts.helm.sh/stable
helm repo update
helm install prometheus-operator stable/prometheus-operatorStep 2: Deploy Thanos Sidecar
Create a file named thanos-sidecar.yaml with the following content:
apiVersion: apps/v1
kind: Deployment
metadata:
name: thanos-sidecar
spec:
selector:
matchLabels:
app: thanos-sidecar
template:
metadata:
labels:
app: thanos-sidecar
spec:
containers:
- name: thanos-sidecar
image: quay.io/thanos/thanos:v0.21.0
args:
- "sidecar"
- "--log.level=info"
- "--http-address=0.0.0.0:19191"
- "--grpc-address=0.0.0.0:10901"
- "--reloader.config-file=/etc/reloader/reload.yaml"
ports:
- containerPort: 19191
- containerPort: 10901
volumeMounts:
- name: config-volume
mountPath: /etc/reloader
volumes:
- name: config-volume
configMap:
name: thanos-reloaderApply the deployment:
kubectl apply -f thanos-sidecar.yamlStep 3: Create Reloader ConfigMap
Create a file named thanos-reloader.yaml:
apiVersion: v1
kind: ConfigMap
metadata:
name: thanos-reloader
data:
reload.yaml: |
rules:
- source_labels: [__address__]
action: keep
regex: prometheus-thanos/prometheusApply the ConfigMap:
kubectl apply -f thanos-reloader.yamlStep 4: Deploy Thanos Receive Component
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm install thanos-receive prometheus-community/prometheus --set-file "alertmanager.thanos-receive.yaml=thanos-receive.yaml"Step 5: Deploy Thanos Store Component
helm install thanos-store prometheus-community/prometheus --set-file "alertmanager.thanos-store.yaml=thanos-store.yaml"Step 6: Create Ingress for Thanos UI (Optional)
If you want to access Thanos UI from outside the cluster, create an Ingress resource.
Step 7: Access Thanos UI
Use kubectl get svc thanos-store-prometheus-community-thanos to get the NodePort of Thanos UI. Access it via http://.
Tips:
- This is a basic setup. Depending on your needs, you might want to customize configurations for Thanos components.
- For production use, ensure you have proper authentication, authorization, and security configurations in place.
- Always refer to the official Thanos documentation for best practices and advanced configurations.
Please note that this is a simplified guide and actual configurations may vary based on your specific environment and requirements. Always refer to the official documentation for Thanos and Prometheus Operator for best practices and advanced configurations.