做个笔记,免得以后忘记
1. 以glusterfs作为后端存储,创建glusterfs volume.
2. 创建namespace monitoring-namespaces.yaml:
apiVersion: v1
kind: Namespace
metadata:
name: monitoring
kubectl create -f monitoring-namespaces.yaml
3. 创建glusterfs endpoint, monitoring-endpoints.json:
{
"kind": "Endpoints",
"apiVersion": "v1",
"metadata": {
"name": "glusterfs-monitoring",
"namespace": "monitoring"
},
"subsets": [
{
"addresses": [
{
"ip": "10.0.115.14"
}
],
"ports": [
{
"port": 24007
}
]
},
{
"addresses": [
{
"ip": "10.0.115.15"
}
],
"ports": [
{
"port": 24007
}
]
}
]
}
kubectl create -f monitoring-endpoints.json
4. 创建PV,monitoring-pv.yaml:
apiVersion: v1
kind: PersistentVolume
metadata:
name: gluster-monitoring-volume
namespace: monitoring
spec:
capacity:
storage: 500Gi
accessModes:
- ReadWriteMany
glusterfs:
endpoints: "glusterfs-monitoring"
path: "monitoring-volume" -- glusterfs volume名称
readOnly: false
5. 创建pvc, glusterfs-prometheus-pvc.yaml:
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: gluster-prometheus
namespace: monitoring
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 100Gi
可看到pvc的状态是bound,
root@node10:~/prometheus# kubectl get pvc -n monitoring
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
gluster-prometheus Bound gluster-monitoring-volume 500Gi RWX 1h
6. 准备prometheus.yaml:
kind: Deployment
metadata:
name: prometheus-deployment
namespace: monitoring
spec:
replicas: 1
selector:
matchLabels:
app: prometheus-server
template:
metadata:
labels:
app: prometheus-server
spec:
securityContext:
runAsUser: 0
containers:
- name: prometheus
image: prom/prometheus:v2.2.0
args:
- "--config.file=/etc/prometheus/prometheus.yml"
- "--storage.tsdb.path=/prometheus/"
ports:
- containerPort: 9090
volumeMounts:
- name: gluster-volume
mountPath: /prometheus/
volumes:
- name: gluster-volume
persistentVolumeClaim:
claimName: gluster-prometheus
7. 创建service,暴露访问端口prometheus-service.yaml:
apiVersion: v1
kind: Service
metadata:
name: prometheus-service
namespace: monitoring
spec:
selector:
app: prometheus-server
type: NodePort
ports:
- port: 8080
targetPort: 9090
nodePort: 30000
即可通过nodeIP:30000访问grafana dashboard了.
注意事项:
1.err="Opening storage failed open DB in /prometheus/: open /prometheus/673409682: permission denied",报这个错误的解决办法是在prometheus.yaml中加上
securityContext:
runAsUser: 0
2. pv,pvc,pod要在同一个namespace下