118 lines
3.8 KiB
YAML
118 lines
3.8 KiB
YAML
---
|
|
# Deploy monitoring stack to Talos cluster via Ansible
|
|
#
|
|
# Prerequisites:
|
|
# - kubectl configured with access to your Talos cluster
|
|
# - kubernetes.core collection installed: ansible-galaxy collection install kubernetes.core
|
|
#
|
|
# Usage:
|
|
# ansible-playbook -i inventory.yml kubernetes-playbook.yml
|
|
#
|
|
# Or with a specific kubeconfig:
|
|
# ansible-playbook -i inventory.yml kubernetes-playbook.yml -e kubeconfig_path=~/.kube/talos-config
|
|
|
|
- name: Deploy monitoring stack to Kubernetes
|
|
hosts: localhost
|
|
connection: local
|
|
gather_facts: false
|
|
|
|
vars:
|
|
kubeconfig_path: "{{ lookup('env', 'KUBECONFIG') | default('~/.kube/config', true) }}"
|
|
manifests_dir: "{{ playbook_dir }}/kubernetes"
|
|
|
|
tasks:
|
|
- name: Create monitoring namespace
|
|
kubernetes.core.k8s:
|
|
kubeconfig: "{{ kubeconfig_path }}"
|
|
state: present
|
|
src: "{{ manifests_dir }}/namespace.yaml"
|
|
|
|
- name: Deploy Prometheus
|
|
kubernetes.core.k8s:
|
|
kubeconfig: "{{ kubeconfig_path }}"
|
|
state: present
|
|
src: "{{ item }}"
|
|
loop:
|
|
- "{{ manifests_dir }}/prometheus/rbac.yaml"
|
|
- "{{ manifests_dir }}/prometheus/configmap.yaml"
|
|
- "{{ manifests_dir }}/prometheus/deployment.yaml"
|
|
- "{{ manifests_dir }}/prometheus/service.yaml"
|
|
|
|
- name: Wait for Prometheus to be ready
|
|
kubernetes.core.k8s_info:
|
|
kubeconfig: "{{ kubeconfig_path }}"
|
|
kind: Deployment
|
|
name: prometheus
|
|
namespace: monitoring
|
|
register: prometheus_deployment
|
|
until: prometheus_deployment.resources[0].status.readyReplicas | default(0) >= 1
|
|
retries: 30
|
|
delay: 10
|
|
|
|
- name: Deploy Loki
|
|
kubernetes.core.k8s:
|
|
kubeconfig: "{{ kubeconfig_path }}"
|
|
state: present
|
|
src: "{{ item }}"
|
|
loop:
|
|
- "{{ manifests_dir }}/loki/configmap.yaml"
|
|
- "{{ manifests_dir }}/loki/deployment.yaml"
|
|
- "{{ manifests_dir }}/loki/service.yaml"
|
|
|
|
- name: Wait for Loki to be ready
|
|
kubernetes.core.k8s_info:
|
|
kubeconfig: "{{ kubeconfig_path }}"
|
|
kind: Deployment
|
|
name: loki
|
|
namespace: monitoring
|
|
register: loki_deployment
|
|
until: loki_deployment.resources[0].status.readyReplicas | default(0) >= 1
|
|
retries: 30
|
|
delay: 10
|
|
|
|
- name: Deploy Promtail
|
|
kubernetes.core.k8s:
|
|
kubeconfig: "{{ kubeconfig_path }}"
|
|
state: present
|
|
src: "{{ item }}"
|
|
loop:
|
|
- "{{ manifests_dir }}/promtail/rbac.yaml"
|
|
- "{{ manifests_dir }}/promtail/configmap.yaml"
|
|
- "{{ manifests_dir }}/promtail/daemonset.yaml"
|
|
|
|
- name: Deploy Node Exporter
|
|
kubernetes.core.k8s:
|
|
kubeconfig: "{{ kubeconfig_path }}"
|
|
state: present
|
|
src: "{{ manifests_dir }}/node-exporter/daemonset.yaml"
|
|
|
|
- name: Deploy Kube State Metrics
|
|
kubernetes.core.k8s:
|
|
kubeconfig: "{{ kubeconfig_path }}"
|
|
state: present
|
|
src: "{{ item }}"
|
|
loop:
|
|
- "{{ manifests_dir }}/kube-state-metrics/rbac.yaml"
|
|
- "{{ manifests_dir }}/kube-state-metrics/deployment.yaml"
|
|
|
|
- name: Get cluster node IPs
|
|
kubernetes.core.k8s_info:
|
|
kubeconfig: "{{ kubeconfig_path }}"
|
|
kind: Node
|
|
register: cluster_nodes
|
|
|
|
- name: Display access information
|
|
ansible.builtin.debug:
|
|
msg:
|
|
- "Monitoring stack deployed successfully!"
|
|
- ""
|
|
- "Prometheus: http://<node-ip>:30090"
|
|
- "Loki: http://<node-ip>:30100"
|
|
- ""
|
|
- "Node IPs:"
|
|
- "{{ cluster_nodes.resources | map(attribute='status.addresses') | flatten | selectattr('type', 'equalto', 'InternalIP') | map(attribute='address') | list }}"
|
|
- ""
|
|
- "Update your RPi inventory.yml with one of these IPs for:"
|
|
- " loki_url: http://<node-ip>:30100"
|
|
- " prometheus_cluster_url: http://<node-ip>:30090"
|