九零不老心
发布于 2019-05-29 / 11 阅读 / 0 评论 / 0 点赞

helm方式安装prometheus

官方参考:https://github.com/helm/charts/tree/master/stable/prometheus
本教程采用阿里云stable/charts
具体用法:helm inspect stable/prometheus
#helm安装prometheus(There are two ways PVs may be provisioned: statically or dynamically.)
一、安装prometheus前需要先配置好kubernetes的存储(提前创建pv、pvc或者安装prometheus的时候指定--set persistentVolume.enabled=false)
    # persistentVolume
        # If true, Prometheus server will create/use a Persistent Volume Claim
        # If false, use emptyDir
    #创建nfs
        教程详见nfs教程
    #创建pv和pvc(本教程使用的静态pv)
        kubectl apply -f pv-and-pvc.yaml
    #说明
        pv和pvc中的storageClassName: nfs-storageclass其实并未创建,只是作为pvc匹配pv的一个属性了(关于这块更多知识请参考:https://kubernetes.io/docs/concepts/storage/persistent-volumes/)
二、安装prometheus
    #因为版本支持限制https://github.com/kubernetes/kube-state-metrics
        #修改了kube-state-metrics image的版本号1.2.0为1.6.0
        #prom/prometheus版本号v2.1.0为v2.10.0
        #prom/pushgateway v0.4.0为v0.8.0
        #prom/alermanager v0.13.0为v0.17.0
        #prom/node-exporter v0.15.2为v0.18.0
        #jimmidyson/configmap-reload v0.1 为v0.2.2
            helm install stable/prometheus  --name prometheus -f ./values.yaml --tls --debug
            helm inspect micro/prometheus | more
            helm install micro/prometheus  --name prometheus --namespace logging -f ./micro-8.14.3.yaml --tls --debug
    #如果发现pod报错:MountVolume.SetUp failed for volume "pv-nfs-243-server" : mount failed: exit status 32 Mounting command: systemd-run Mounting arguments: --description=Kubernetes transient mount for /var/lib/kubelet/pods/f1ded27e-7c77-11e9-9cea-000c298cc8b3/volumes/kubernetes.io~nfs/pv-nfs-243-server --scope -- mount -t nfs 192.168.10.243:/nfs/data/prometheus/server /var/lib/kubelet/pods/f1ded27e-7c77-11e9-9cea-000c298cc8b3/volumes/kubernetes.io~nfs/pv-nfs-243-server Output: Running scope as unit run-52162.scope. mount: wrong fs type, bad option, bad superblock on 192.168.10.243:/nfs/data/prometheus/server, missing codepage or helper program, or other error (for several filesystems (e.g. nfs, cifs) you might need a /sbin/mount.<type> helper program) In some cases useful info is found in syslog - try dmesg | tail or so.Back-off restarting failed container
       # 那是因为pod部署的node节点没有安装nfs-util,无法识别nfs文件系统类型
            yum install -y nfs-utils #问题解决
    #pod prometheus-prometheus-server状态Init:CrashLoopBackOff报错 Back-off restarting failed container,初始化init-chown-data容器失败chown -R 65534:65534 /data
        #那是因为nfs目录权限问题
            vi /etc/exports
                添加no_root_squash #/nfs *(rw)改为/nfs *(rw,no_root_squash) #问题解决
    #查看prometheus状态
        helm status prometheus --tls
三、访问(我配置了dnsmasq.conf address=/kubernetes.ingress/192.168.10.240)
    https://prometheus.kubernetes.ingress:32443/
        https://prometheus.kubernetes.ingress:32443/targets
        https://prometheus.kubernetes.ingress:32443/service-discovery
    https://pushgateway.kubernetes.ingress:32443/
    https://alertmanager.kubernetes.ingress:32443/
    
四、如何卸载prometheus
    helm delete --purge prometheus --tls
五、注意,因为prometheus首页默认有个跳转/的js,所以ingress path设置是/

六、升级
    helm upgrade prometheus micro/prometheus -f ./micro-8.14.3.yaml --tls --debug

注意:https://github.com/kubernetes/kube-state-metrics
    kube-state-meterics等组件对于k8s版本的支持

直接粘贴笔记,格式不太美观,教程原文件及yaml配置文件,可以直接百度云下载后浏览:https://pan.baidu.com/s/14KArQ7yWhqWJEgcVZrxE6Q 提取码:86mq