Prometheus has become a fundamental component of many Kubernetes-based monitoring solutions. RealTheory can notify you if Prometheus is a required component in your environment that is not present on your cluster or if the version of Prometheus that is installed is not in compliance with organizational standards.
If Prometheus is a required component in your Kubernetes environment, it is most likely that a Prometheus Helm chart or the yaml files for a Prometheus ConfigMap, Deployment, and Service already exist. Contact your Operations or DevOps team to determine if there are company resources for installing Prometheus BEFORE using either of the following procedures.
To install Prometheus:
helm repo add prometheus-community https://prometheus-community.github.io/helm-chartshelm install prometheus prometheus-community/prometheushelm install prometheus prometheus-community/prometheus --version <version><version>To install Prometheus:
1# namespace.yaml2apiVersion: v13kind: Namespace4metadata:5name: prometheus
kubectl apply -f namespace.yamlprometheus-configmap.yaml). 1# prometheus-configmap.yaml2apiVersion: v13kind: ConfigMap4metadata:5name: prometheus-server-conf6namespace: prometheus7data:8prometheus.yaml: |9global:10scrape_interval: 15s11scrape_configs:12- job_name: 'prometheus'13static_configs:14- targets: [<services, applications, or infrastructure components>]
where -targets: is an array that contains the addresses (in the format hostname:port) of the endpoints or services exposing metrics.
kubectl apply -f prometheus-configmap.yaml1# prometheus-deployment.yaml2apiVersion: apps/v13kind: Deployment4metadata:5name: prometheus-server6namespace: prometheus7spec:8replicas: 19selector:10matchLabels:11app: prometheus-server12template:13metadata:14labels:15app: prometheus-server16spec:17containers:18- name: prometheus19image: prom/prometheus:latest20ports:21- containerPort: 909022volumeMounts:23- name: prometheus-server-conf24mountPath: /etc/prometheus/prometheus.yml25subPath: prometheus.yaml26volumes:27- name: prometheus-server-conf28configMap:29name: prometheus-server-conf
kubectl apply -f prometheus-deployment.yaml1# prometheus-service.yaml2apiVersion: v13kind: Service4metadata:5name: prometheus-server6namespace: prometheus7spec:8selector:9app: prometheus-server10ports:11- name: web12port: 8013targetPort: 9090
kubectl apply -f prometheus-service.yamlkubectl get pods -n <namespace> <namespace> is the namespace where Prometheus is installed.If a specific version of Prometheus is required in your Kubernetes environment, it is most likely that a Prometheus Helm chart or yaml files for a Prometheus ConfigMap, Deployment, and Service already exist. Contact your Operations or DevOps team to determine if there are company resources for installing Prometheus BEFORE using either of the following procedures.
To upgrade Prometheus:
helm repo add prometheus-community https://prometheus-community.github.io/helm-chartshelm search repo prometheus-community/prometheus --versionshelm upgrade prometheus prometheus-community/prometheus --version <version> <version> is the version of Prometheus you want to upgrade to.kubectl get pods -n <namespace> <namespace> is the namespace where Prometheus is installed.To upgrade Prometheus:
kubectl edit configmap prometheus-server-conf -n <namespace>1# updated-prometheus-configmap.yaml2apiVersion: v13kind: ConfigMap4metadata:5name: prometheus-server-conf6namespace: prometheus7data:8prometheus.yaml: |9global:10scrape_interval: 15s11scrape_configs:12- job_name: 'prometheus'13static_configs:14- targets: [<services, applications, or infrastructure components>]
where -targets: is an array that contains the addresses (in the format hostname:port) of the endpoints or services exposing metrics.
kubectl apply -f updated-prometheus-configmap.yamlkubectl edit deployment prometheus-server -n <namespace>1# updated-prometheus-deployment.yaml2apiVersion: apps/v13kind: Deployment4metadata:5name: prometheus-server6namespace: prometheus7spec:8replicas: 19selector:10matchLabels:11app: prometheus-server12template:13metadata:14labels:15app: prometheus-server16spec:17containers:18- name: prometheus19image: prom/prometheus:latest20ports:21- containerPort: 909022volumeMounts:23- name: prometheus-server-conf24mountPath: /etc/prometheus/prometheus.yml25subPath: prometheus.yaml26volumes:27- name: prometheus-server-conf28configMap:29name: prometheus-server-conf
kubectl apply -f updated-prometheus-deployment.yamlkubectl scale deployment prometheus-server --replicas=0 -n <namespace> kubectl scale deployment prometheus-server --replicas=1 -n <namespace>kubectl get pods -n <namespace> <namespace> is the namespace where Prometheus is installed.Search for a command to run...