手动部署prometheus
docker方式部署
1. 先搭建k8s环境
https://blog.csdn.net/weixin_45842014/article/details/108757132
2. 创建kube-ops命名空间(master)
cd /usr/local/src
mkdir prometheus
cd prometheus
vim prom-ns.yaml -----编辑文件
apiVersion: v1
kind: Namespace
metadata:
name: kube-ops
labels:
name: kube-ops
kubectl create -f prom-ns.yaml -----创建kube-ops命名空间
[root@k8s-master src]# kubectl get ns -A
NAME STATUS AGE
kube-ops Active 12s
cd /usr/local/src
mkdir prometheus
cd prometheus
vim prom-sa.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: prometheus
namespace: kube-ops
[root@k8s-master prometheus]# kubectl get sa -A|grep prometheus
kube-ops prometheus 1 4h46m
yum -y install rpcbind nfs-utils
systemctl start rpcbind
systemctl start nfs
vim /etc/exports
mkdir /data/k8s
cd
ls
ll /data
mkdir -p /data/k8s
showmount -e
cd prometheus/
vim prom-pv.yaml
kubectl create -f prom-pv.yaml
vim prom-pv.yaml
kubectl create -f prom-pv.yaml
[root@k8s-master prometheus]# kubectl get pv -A
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
prometheus 10Gi RWO Recycle Bound kube-ops/prometheus 145m
vim prom-pvc.yaml
kubectl create -f prom-pvc.yaml
vim prom-pvc.yaml
kubectl create -f prom-pvc.yaml
kubectl get pvc
vim prom-pvc.yaml
[root@k8s-master prometheus]# kubectl get pvc -n kube-ops
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
prometheus Bound prometheus 10Gi RWO 140m
vim prom-cm.yaml
kubectl create -f prom-cm.yaml
[root@k8s-master prometheus]# kubectl get cm -n kube-ops
NAME DATA AGE
prometheus-config 1 93m
vim prom-clusterrole.yaml
kubectl create -f prom-clusterrole.yaml
[root@k8s-master prometheus]# kubectl get clusterrole -n kube-ops|grep prometheus
prometheus
[root@k8s-master prometheus]# kubectl describe clusterrole prometheus -n kube-ops
Name: prometheus
Labels: <none>
Annotations: <none>
PolicyRule:
Resources Non-Resource URLs Resource Names Verbs
--------- ----------------- -------------- -----
endpoints [] [] [get list watch]
nodes/proxy [] [] [get list watch]
nodes [] [] [get list watch]
pods [] [] [get list watch]
services [] [] [get list watch]
[/metrics] [] [get]
configmaps [] [] [get]
nodes/metrics [] [] [get]
vim prom-clusterrole.yaml
vim prome-clusterrolebind.yaml
[root@k8s-master prometheus]# kubectl get clusterrolebindings -n kube-ops|grep prometheus
prometheus
vim prom-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: prometheus
namespace: kube-ops
labels:
app: prometheus
spec:
selector:
matchLabels:
app: prometheus
template:
metadata:
labels:
app: prometheus
spec:
serviceAccountName: prometheus
containers:
- image: prom/prometheus:v2.4.3
name: prometheus
command:
- "/bin/prometheus"
args:
- "--config.file=/etc/prometheus/prometheus.yml"
- "--storage.tsdb.path=/prometheus"
- "--storage.tsdb.retention=24h"
- "--web.enable-admin-api"
- "--config.file=/etc/prometheus/prometheus.yml"
- "--storage.tsdb.path=/prometheus"
- "--storage.tsdb.retention=24h"
- "--web.enable-admin-api"
- "--web.enable-lifecycle"
ports:
- containerPort: 9090
protocol: TCP
name: http
volumeMounts:
- mountPath: "/prometheus"
subPath: prometheus
name: data
- mountPath: "/etc/prometheus"
name: config-volume
resources:
requests:
cpu: 100m
memory: 100Mi
limits:
cpu: 100m
memory: 100Mi
securityContext:
runAsUser: 0
volumes:
- name: data
persistentVolumeClaim:
claimName: prometheus
- name: config-volume
configMap:
name: prometheus-config