千家信息网

prometheus08-k8s部署prometheus

发表于:2024-11-27 作者:千家信息网编辑
千家信息网最后更新 2024年11月27日,1.基础环境有k8s集群[root@kubemaster01 prometheus]# kubectl get node NAME STATUS ROLES AGE
千家信息网最后更新 2024年11月27日prometheus08-k8s部署prometheus

1.基础环境有k8s集群

[root@kubemaster01 prometheus]# kubectl  get node NAME             STATUS   ROLES    AGE   VERSION192.168.249.51   Ready       63d   v1.12.3192.168.249.52   Ready       63d   v1.12.3192.168.249.53   Ready       63d   v1.12.3You have new mail in /var/spool/mail/root[root@kubemaster01 prometheus]# kubectl  get csNAME                 STATUS    MESSAGE             ERRORscheduler            Healthy   ok                  controller-manager   Healthy   ok                  etcd-1               Healthy   {"health":"true"}   etcd-2               Healthy   {"health":"true"}   etcd-0               Healthy   {"health":"true"}   [root@kubemaster01 prometheus]#

2.下载prometheus yaml

for file in  prometheus-configmap.yaml prometheus-rbac.yaml prometheus-service.yaml prometheus-statefulset.yaml ;do wget https://raw.githubusercontent.com/kubernetes/kubernetes/master/cluster/addons/prometheus/$file;done

3.设置动态storageclass

3.1.kubectl apply -f rbac.yml

kind: ServiceAccountapiVersion: v1metadata:  name: nfs-client-provisioner---kind: ClusterRoleapiVersion: rbac.authorization.k8s.io/v1metadata:  name: nfs-client-provisioner-runnerrules:  - apiGroups: [""]    resources: ["persistentvolumes"]    verbs: ["get", "list", "watch", "create", "delete"]  - apiGroups: [""]    resources: ["persistentvolumeclaims"]    verbs: ["get", "list", "watch", "update"]  - apiGroups: ["storage.k8s.io"]    resources: ["storageclasses"]    verbs: ["get", "list", "watch"]  - apiGroups: [""]    resources: ["events"]    verbs: ["create", "update", "patch"]---kind: ClusterRoleBindingapiVersion: rbac.authorization.k8s.io/v1metadata:  name: run-nfs-client-provisionersubjects:  - kind: ServiceAccount    name: nfs-client-provisioner    namespace: defaultroleRef:  kind: ClusterRole  name: nfs-client-provisioner-runner  apiGroup: rbac.authorization.k8s.io---kind: RoleapiVersion: rbac.authorization.k8s.io/v1metadata:  name: leader-locking-nfs-client-provisionerrules:  - apiGroups: [""]    resources: ["endpoints"]    verbs: ["get", "list", "watch", "create", "update", "patch"]---kind: RoleBindingapiVersion: rbac.authorization.k8s.io/v1metadata:  name: leader-locking-nfs-client-provisionersubjects:  - kind: ServiceAccount    name: nfs-client-provisioner    namespace: defaultroleRef:  kind: Role  name: leader-locking-nfs-client-provisioner  apiGroup: rbac.authorization.k8s.io

3.2 设置存储deployment.yaml

apiVersion: v1kind: ServiceAccountmetadata:  name: nfs-client-provisioner---kind: DeploymentapiVersion: apps/v1metadata:  name: nfs-client-provisionerspec:  replicas: 1  selector:    matchLabels:      app: nfs-client-provisioner  strategy:    type: Recreate  template:    metadata:      labels:        app: nfs-client-provisioner    spec:      serviceAccountName: nfs-client-provisioner      containers:        - name: nfs-client-provisioner          image: quay.io/external_storage/nfs-client-provisioner:latest          volumeMounts:            - name: nfs-client-root              mountPath: /persistentvolumes          env:            - name: PROVISIONER_NAME              value: fuseim.pri/ifs            - name: NFS_SERVER              value: 192.168.249.54            - name: NFS_PATH              value: /data/k8s/prometheus      volumes:        - name: nfs-client-root          nfs:            server: 192.168.249.54            path: /data/k8s/prometheus

3.4 kubectl apply -f class.yaml

apiVersion: storage.k8s.io/v1kind: StorageClassmetadata:  name: managed-nfs-storageprovisioner: fuseim.pri/ifs # or choose another name, must match deployment's env PROVISIONER_NAME'parameters:  archiveOnDelete: "false"

3.5 备注说明 nfs 是提前部署好的(ip:192.168.249.54)

[root@es prometheus]# cat /etc/exports/data/k8s/prometheus  192.168.249.0/24(rw,sync,no_root_squash)[root@es prometheus]#

4.修改prometheus的存储地址(prometheus-statefulset.yaml)

4.把 prometheus的svc 发布改为nodeport

5.部署

kubectl apply -f prometheus-rbac.yaml prometheus-configmap.yaml prometheus-statefulset.yaml prometheus-service.yaml

6. 访问

7.

0