Helm/Prometheus: Difference between revisions
Jump to navigation
Jump to search
Line 20: | Line 20: | ||
hosts: | hosts: | ||
- prometheus.k8s.local | - prometheus.k8s.local | ||
YML | |||
</syntaxhighlight> | |||
==ConfigMap== | |||
<syntaxhighlight lang="yaml"> | |||
cat <<-'YML' | kubectl -n prometheus apply -f - | |||
apiVersion: v1 | |||
kind: ConfigMap | |||
metadata: | |||
name: prometheus-server-conf | |||
namespace: prometheus | |||
data: | |||
prometheus.yml: | | |||
global: | |||
scrape_interval: 15s | |||
scrape_configs: | |||
- job_name: 'kubernetes-apiservers' | |||
kubernetes_sd_configs: | |||
- role: endpoints | |||
relabel_configs: | |||
- source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_service_name, __meta_kubernetes_endpoint_port_name] | |||
action: keep | |||
regex: default;kubernetes;https | |||
- job_name: 'kubernetes-nodes' | |||
scheme: https | |||
tls_config: | |||
ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt | |||
insecure_skip_verify: true | |||
bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token | |||
kubernetes_sd_configs: | |||
- role: node | |||
relabel_configs: | |||
- action: labelmap | |||
regex: __meta_kubernetes_node_label_(.+) | |||
- target_label: __address__ | |||
replacement: kubernetes.default.svc:443 | |||
- source_labels: [__meta_kubernetes_node_name] | |||
regex: (.+) | |||
target_label: __metrics_path__ | |||
replacement: /api/v1/nodes/${1}/proxy/metrics | |||
- job_name: 'metrics-server' | |||
kubernetes_sd_configs: | |||
- role: endpoints | |||
relabel_configs: | |||
- source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_service_name, __meta_kubernetes_endpoint_port_name] | |||
action: keep | |||
regex: kube-system;metrics-server;https | |||
YML | YML | ||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 01:26, 2 July 2024
helm repo add prometheus https://prometheus-community.github.io/helm-charts helm repo update helm repo list
Config
export KUBECONFIG="${HOME}/.kube/dev-kubeconfig.yaml"
export KUBECONFIG="${HOME}/.kube/gcp-kubeconfig.yaml"
export KUBECONFIG="${HOME}/.kube/config"
Install
kubectl create namespace prometheus
helm show values prometheus/prometheus
cat <<YML | helm install -n prometheus prometheus prometheus/prometheus -f -
server:
ingress:
enabled: true
hosts:
- prometheus.k8s.local
YML
ConfigMap
cat <<-'YML' | kubectl -n prometheus apply -f -
apiVersion: v1
kind: ConfigMap
metadata:
name: prometheus-server-conf
namespace: prometheus
data:
prometheus.yml: |
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'kubernetes-apiservers'
kubernetes_sd_configs:
- role: endpoints
relabel_configs:
- source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_service_name, __meta_kubernetes_endpoint_port_name]
action: keep
regex: default;kubernetes;https
- job_name: 'kubernetes-nodes'
scheme: https
tls_config:
ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
insecure_skip_verify: true
bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
kubernetes_sd_configs:
- role: node
relabel_configs:
- action: labelmap
regex: __meta_kubernetes_node_label_(.+)
- target_label: __address__
replacement: kubernetes.default.svc:443
- source_labels: [__meta_kubernetes_node_name]
regex: (.+)
target_label: __metrics_path__
replacement: /api/v1/nodes/${1}/proxy/metrics
- job_name: 'metrics-server'
kubernetes_sd_configs:
- role: endpoints
relabel_configs:
- source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_service_name, __meta_kubernetes_endpoint_port_name]
action: keep
regex: kube-system;metrics-server;https
YML
Uninstall
helm uninstall -n prometheus prometheus
helm delete -n prometheus prometheus
Playground
helm upgrade --install -f values.yaml prometheus prometheus/prometheus
helm upgrade --install prometheus prometheus/prometheus
helm show values prometheus/prometheus
|
kubectl exec -n prometheus -it prometheus-6fd8886fd4-4vwgh -- cat /etc/os-release
kubectl exec -n prometheus -it prometheus-6fd8886fd4-4vwgh -- bash
kubectl exec -n prometheus -it prometheus-6fd8886fd4-4vwgh -- sh
|
| |
kubectl delete all --all -n prometheus
kubectl delete ing --all -n prometheus
kubectl delete sts --all -n prometheus
|
kubectl delete svc --all -n prometheus
kubectl delete pvc --all -n prometheus
kubectl delete pv --all -n prometheus
|
| |
kubectl logs -f prometheus-6fd8886fd4-4vwgh -n prometheus
kubectl rollout restart deploy prometheus -n prometheus
kubectl rollout restart sts prometheus -n prometheus
kubectl logs -f prometheus-hash -n prometheus
|
kubectl config --kubeconfig=${HOME}/.kube/aws-kubeconfig.yaml view --flatten
kubectl config --kubeconfig=${HOME}/.kube/dev-kubeconfig.yaml view --flatten
kubectl config --kubeconfig=${HOME}/.kube/gcp-kubeconfig.yaml view --flatten
kubectl config --kubeconfig=${HOME}/.kube/config view --flatten
|
| |
kubectl get secret -n prometheus prometheus -o json|jq -r '.data."admin-password"'|base64 -d;echo
kubectl get secret -n prometheus prometheus -o json|jq -r '.data."admin-user"'|base64 -d;echo
|
References
| ||
| ||