Helm/Prometheus: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
(20 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
helm repo add prometheus https://prometheus-community.github.io/helm-charts | helm repo add prometheus https://prometheus-community.github.io/helm-charts | ||
helm repo update | helm repo update && helm repo list | ||
kubectl config get-contexts | |||
==Config== | ==Config== | ||
Line 13: | Line 13: | ||
<syntaxhighlight lang="yaml"> | <syntaxhighlight lang="yaml"> | ||
kubectl create namespace prometheus | kubectl create namespace prometheus | ||
helm show values prometheus/prometheus | helm show values prometheus/prometheus|less | ||
cat <<YML | helm install -n prometheus prometheus prometheus/prometheus -f - | cat <<YML | helm install -n prometheus prometheus prometheus/prometheus -f - | ||
ingress: | server: | ||
ingress: | |||
hosts: | enabled: true | ||
hosts: | |||
- prometheus.k8s.local | |||
tls: | |||
- secretName: prometheus.k8s.local.tls | |||
hosts: | |||
- prometheus.k8s.local | |||
YML | YML | ||
</syntaxhighlight> | |||
==ConfigMap== | |||
<syntaxhighlight lang="bash"> | |||
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 | |||
kubectl -n prometheus get cm prometheus-server-conf -o yaml | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 30: | Line 91: | ||
==Playground== | ==Playground== | ||
{| | {| | ||
| valign="top" colspan="2" | | |||
<syntaxhighlight lang="bash"> | |||
PROMETHEUS_PUSH_POD_NAME="$(kubectl -n prometheus get pod -l 'app.kubernetes.io/name=prometheus-pushgateway' -o json|jq -r '.items[0].metadata.name')" | |||
PROMETHEUS_STATE_POD_NAME="$(kubectl -n prometheus get pod -l 'app.kubernetes.io/name=kube-state-metrics' -o json|jq -r '.items[0].metadata.name')" | |||
PROMETHEUS_POD_NAME="$(kubectl -n prometheus get pod -l 'app.kubernetes.io/name=prometheus' -o json|jq -r '.items[0].metadata.name')" | |||
</syntaxhighlight> | |||
|- | |||
| colspan="2" | | |||
---- | |||
|- | |||
| valign="top" | | | valign="top" | | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
helm upgrade --install -f values.yaml prometheus prometheus/prometheus | helm upgrade --install -f values.yaml prometheus prometheus/prometheus | ||
helm upgrade --install prometheus prometheus/prometheus | helm upgrade --install prometheus prometheus/prometheus | ||
helm show values prometheus/prometheus | helm show values prometheus/prometheus|less | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| valign="top" | | | valign="top" | | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
kubectl | kubectl -n prometheus exec -it ${PROMETHEUS_POD_NAME} -- cat /etc/config/prometheus.yml | ||
kubectl | kubectl -n prometheus exec -it ${PROMETHEUS_POD_NAME} -- ls -lah /etc/config/ | ||
kubectl | kubectl -n prometheus exec -it ${PROMETHEUS_POD_NAME} -- /bin/sh | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 50: | Line 122: | ||
| valign="top" | | | valign="top" | | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
kubectl | kubectl -n prometheus logs -f ${PROMETHEUS_POD_NAME} | ||
kubectl | kubectl -n prometheus rollout restart deploy prometheus-server | ||
kubectl | kubectl -n prometheus logs -f prometheus-server-hash | ||
</syntaxhighlight> | |||
| valign="top" | | |||
<syntaxhighlight lang="bash"> | |||
kubectl config --kubeconfig=${HOME}/.kube/aws-kubeconfig.yaml view --flatten | |||
kubectl config --kubeconfig=${HOME}/.kube/gcp-kubeconfig.yaml view --flatten | |||
kubectl config --kubeconfig=${HOME}/.kube/config view --flatten | |||
</syntaxhighlight> | </syntaxhighlight> | ||
|- | |||
| colspan="2" | | |||
---- | |||
|- | |||
| valign="top" | | | valign="top" | | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
kubectl | kubectl -n prometheus get cm prometheus-server-conf -o yaml | ||
kubectl | kubectl -n prometheus edit deploy prometheus-server -o yaml | ||
kubectl -n prometheus get deploy prometheus-server -o yaml | |||
</syntaxhighlight> | </syntaxhighlight> | ||
| valign="top" | | |||
prometheus-prometheus-pushgateway.prometheus.svc.cluster.local:9091 | |||
prometheus-alertmanager.prometheus.svc.cluster.local | |||
prometheus-server.prometheus.svc.cluster.local | |||
|- | |- | ||
Line 68: | Line 156: | ||
| valign="top" | | | valign="top" | | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
kubectl | kubectl -n prometheus delete all --all | ||
kubectl | kubectl -n prometheus delete ing --all | ||
kubectl | kubectl -n prometheus delete sts --all | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| valign="top" | | | valign="top" | | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
kubectl | kubectl -n prometheus delete svc --all | ||
kubectl -n prometheus delete pvc --all | |||
kubectl | kubectl -n prometheus delete pv --all | ||
kubectl | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 86: | Line 172: | ||
---- | ---- | ||
|- | |- | ||
| valign="top | | valign="top" | | ||
| valign="top" | | |||
|} | |} | ||
Line 99: | Line 183: | ||
* [https://stackoverflow.com/questions/75596795/ Helm » Pass YAML/JSON using <code>stdin</code>] | * [https://stackoverflow.com/questions/75596795/ Helm » Pass YAML/JSON using <code>stdin</code>] | ||
* [https://github.com/prometheus-community/helm-charts Helm » Prometheus » GitHub] | * [https://github.com/prometheus-community/helm-charts Helm » Prometheus » GitHub] | ||
* [[Helm/Prometheus Stack|Helm » Prometheus Stack]] | |||
* [[Helm/Cert Manager|Helm » Cert Manager]] | |||
* [https://artifacthub.io/packages/helm/prometheus-community/prometheus Helm » Prometheus] | * [https://artifacthub.io/packages/helm/prometheus-community/prometheus Helm » Prometheus] | ||
* [[Helm]] | * [[Helm]] | ||
Line 112: | Line 198: | ||
| valign="top" | | | valign="top" | | ||
* [https://spacelift.io/blog/prometheus-helm-chart Prometheus » Spacelift » Blog] | * [https://spacelift.io/blog/prometheus-helm-chart Prometheus » Spacelift » Blog] | ||
* [https://prometheus.io/docs/instrumenting/clientlibs/ Prometheus » Client Libraries] | |||
* [https://grafana.com/grafana/dashboards/315-kubernetes-cluster-monitoring-via-prometheus/ Prometheus » K8s » Grafana] | * [https://grafana.com/grafana/dashboards/315-kubernetes-cluster-monitoring-via-prometheus/ Prometheus » K8s » Grafana] | ||
* [https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/ Prometheus » Alerting Rules] | |||
* [https://prometheus.io/docs/prometheus/latest/configuration/configuration/ Prometheus » Configuration] | |||
* [https://prometheus.io/docs/concepts/data_model/ Prometheus » Data Model] | |||
* [https://prometheus.io/docs/visualization/grafana/ Prometheus » Grafana] | |||
* [https://prometheus.io/docs/prometheus/latest/querying/basics/ Prometheus » Quering] | |||
* [https://prometheus.io/docs/prometheus/latest/storage/ Prometheus » Storage] | |||
* [https://prometheus.io/ Prometheus] | * [https://prometheus.io/ Prometheus] | ||
| valign="top" | | | valign="top" | | ||
* [https://prometheus.io/docs/instrumenting/exporters/ Prometheus » Exporters] | |||
| valign="top" | | | valign="top" | | ||
Line 136: | Line 230: | ||
| valign="top" | | | valign="top" | | ||
* [[K8s/CSI Hostpath Driver|K8s » CSI Hostpath Driver]] | |||
| valign="top" | | | valign="top" | | ||
|} | |} |
Latest revision as of 12:14, 22 August 2024
helm repo add prometheus https://prometheus-community.github.io/helm-charts helm repo update && helm repo list kubectl config get-contexts
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|less
cat <<YML | helm install -n prometheus prometheus prometheus/prometheus -f -
server:
ingress:
enabled: true
hosts:
- prometheus.k8s.local
tls:
- secretName: prometheus.k8s.local.tls
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
kubectl -n prometheus get cm prometheus-server-conf -o yaml
Uninstall
helm uninstall -n prometheus prometheus
helm delete -n prometheus prometheus
Playground
PROMETHEUS_PUSH_POD_NAME="$(kubectl -n prometheus get pod -l 'app.kubernetes.io/name=prometheus-pushgateway' -o json|jq -r '.items[0].metadata.name')"
PROMETHEUS_STATE_POD_NAME="$(kubectl -n prometheus get pod -l 'app.kubernetes.io/name=kube-state-metrics' -o json|jq -r '.items[0].metadata.name')"
PROMETHEUS_POD_NAME="$(kubectl -n prometheus get pod -l 'app.kubernetes.io/name=prometheus' -o json|jq -r '.items[0].metadata.name')"
| |
| |
helm upgrade --install -f values.yaml prometheus prometheus/prometheus
helm upgrade --install prometheus prometheus/prometheus
helm show values prometheus/prometheus|less
|
kubectl -n prometheus exec -it ${PROMETHEUS_POD_NAME} -- cat /etc/config/prometheus.yml
kubectl -n prometheus exec -it ${PROMETHEUS_POD_NAME} -- ls -lah /etc/config/
kubectl -n prometheus exec -it ${PROMETHEUS_POD_NAME} -- /bin/sh
|
| |
kubectl -n prometheus logs -f ${PROMETHEUS_POD_NAME}
kubectl -n prometheus rollout restart deploy prometheus-server
kubectl -n prometheus logs -f prometheus-server-hash
|
kubectl config --kubeconfig=${HOME}/.kube/aws-kubeconfig.yaml view --flatten
kubectl config --kubeconfig=${HOME}/.kube/gcp-kubeconfig.yaml view --flatten
kubectl config --kubeconfig=${HOME}/.kube/config view --flatten
|
| |
kubectl -n prometheus get cm prometheus-server-conf -o yaml
kubectl -n prometheus edit deploy prometheus-server -o yaml
kubectl -n prometheus get deploy prometheus-server -o yaml
|
prometheus-prometheus-pushgateway.prometheus.svc.cluster.local:9091 prometheus-alertmanager.prometheus.svc.cluster.local prometheus-server.prometheus.svc.cluster.local |
| |
kubectl -n prometheus delete all --all
kubectl -n prometheus delete ing --all
kubectl -n prometheus delete sts --all
|
kubectl -n prometheus delete svc --all
kubectl -n prometheus delete pvc --all
kubectl -n prometheus delete pv --all
|
| |
References
| ||
| ||