Deploy prometheus
To install Prometheus on a Kubernetes cluster, you can create and apply Kubernetes manifests directly.
- Create Namespace (optional):
You can create a dedicated namespace for Prometheus to keep your resources organized. To create a namespace, use:
kubectl create namespace prometheus
Create a "prometheus.yaml" configuration file. This file defines the Prometheus server's configuration and service:
apiVersion: v1
kind: Service
metadata:
name: prometheus
labels:
app: prometheus
spec:
selector:
app: prometheus
ports:
- name: web
port: 9090
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: prometheus
labels:
app: prometheus
spec:
replicas: 1
selector:
matchLabels:
app: prometheus
template:
metadata:
labels:
app: prometheus
spec:
containers:
- name: prometheus
image: prom/prometheus:v2.28.1
args:
- "--config.file=/etc/prometheus/prometheus.yml"
- "--storage.tsdb.path=/prometheus/data"
ports:
- containerPort: 9090
volumeMounts:
- name: prometheus-config
mountPath: /etc/prometheus
- name: prometheus-data
mountPath: /prometheus/data
volumes:
- name: prometheus-config
configMap:
name: prometheus-config
- name: prometheus-data
emptyDir: {}
Create a "prometheus-config.yaml" configuration file to define the Prometheus server's configuration:
apiVersion: v1
kind: ConfigMap
metadata:
name: prometheus-config
data:
prometheus.yml: |
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
# Add more scrape configurations as needed for your services.
You can customize the "prometheus.yml" file to include targets for your applications and services.
kubectl apply -f prometheus-config.yaml
kubectl apply -f prometheus.yaml
You can access Prometheus by port-forwarding or setting up a service depending on your use case. For example, to port-forward the Prometheus web interface:
kubectl port-forward svc/prometheus 9090:9090
Then, you can access Prometheus at "http://localhost:9090" in your web browser.
Remember to adjust these configurations to your specific needs. This guide provides a basic setup for Prometheus, and you can expand it to include additional scrape configurations and integrations as required for your environment.