kube-prometheus 部署指南
1、介绍:
略
2、版本:
Kubernetes 版本:1.16.2
Docker 版本:18.09.9
Kube-prometheus 版本:0.2.0
3、下载 kube-prometheus 镜像部署文件
前往 github 上下载 0.2.0 版本的压缩包
4、进入源码的 manifests 文件夹
cd kube-prometheus/manifests/
5、修改源码文件,将 service 以 NodePort 的方式提供服务
vim prometheus-service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
prometheus: k8s
name: prometheus-k8s
namespace: monitoring
spec:
type: NodePort
ports:
- name: http
port: 9090
targetPort: web
nodePort: 9090
selector:
app: prometheus
prometheus: k8s
sessionAffinity: ClientIP
vim alertmanager-service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: grafana
name: grafana
namespace: monitoring
spec:
type: NodePort
ports:
- name: http
port: 3000
targetPort: http
nodePort: 3000
selector:
app: grafana
vim prometheus-service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
alertmanager: main
name: alertmanager-main
namespace: monitoring
spec:
type: NodePort
ports:
- name: web
port: 9093
targetPort: web
nodePort: 9093
selector:
alertmanager: main
app: alertmanager
sessionAffinity: ClientIP
6、修改配置文件设置 prometheus 历史数据保存 15 天,并且使用 ceph 设置数据持久化
vim 00StorageClass.yaml
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: cephfs
provisioner: ceph.com/cephfs
parameters:
monitors: 192.168.10.101:6789,192.168.10.102:6789,192.168.10.103:6789
adminId: admin
adminSecretName: ceph-admin-secret
adminSecretNamespace: "kube-system"
claimRoot: /volumes/kubernetes
修改prometheus部署文件
vim prometheus-prometheus.yaml
apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
labels:
prometheus: k8s
name: k8s
namespace: monitoring
spec:
alerting:
alertmanagers:
- name: alertmanager-main
namespace: monitoring
port: web
baseImage: quay.io/prometheus/prometheus
nodeSelector:
kubernetes.io/os: linux
podMonitorSelector: {}
replicas: 2
retention: 15d #设置历史数据保存15天
resources:
requests:
memory: 400Mi
ruleSelector:
matchLabels:
prometheus: k8s
role: alert-rules
securityContext:
fsGroup: 0 #一定修改不然会有权限错误
runAsNonRoot: false#一定修改不然会有权限错误
runAsUser: 0#一定修改不然会有权限错误
serviceAccountName: prometheus-k8s
serviceMonitorNamespaceSelector: {}
serviceMonitorSelector: {}
version: v2.11.0
storage:
volumeClaimTemplate:
spec:
storageClassName: cephfs
resources:
requests:
storage: 20Gi
7、设置 grafana 持久化
先创建pvc文件
vim 00grafana-pvc.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: grafana
namespace: monitoring #指定monitoring
spec:
storageClassName: cephfs #指定StorageClass
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
8、监控 kube-controller-manager 和 kube-scheduler 这两个系统组件
创建两个 service 对应上述系统组件
vim 00kube-scheduler-service.yaml
apiVersion: v1
kind: Service
metadata:
namespace: kube-system
name: kube-scheduler
labels:
k8s-app: kube-scheduler
spec:
selector:
component: kube-scheduler
ports:
- name: http-metrics
port: 10251
targetPort: 10251
protocol: TCP
vim 00kube-controller-manager-service.yaml
apiVersion: v1
kind: Service
metadata:
namespace: kube-system
name: kube-controller-manager
labels:
k8s-app: kube-controller-manager
spec:
selector:
component: kube-controller-manager
ports:
- name: http-metrics
port: 10252
targetPort: 10252
protocol: TCP
修改grafana部署文件
- name: grafana-storage
persistentVolumeClaim:
claimName: grafana
9、现在就可以 apply 文件了
kubectl apply
-
f .