云容器实例 CCI-使用Prometheus监控CCI实例:使用Deployment部署Prometheus
使用Deployment部署Prometheus
创建prometheus的工作负载,将配置项挂载到工作负载中。使用Deployment部署Prometheus所用的镜像,相比于官方镜像额外打包了cci-iam-authenticator二进制。
示例中创建一个名为prometheus-config的Volume,Volume引用名为“prometheus-config”、“kubeconfig”、“prometheus-storage”的ConfigMap,再将Volume挂载到容器的“/tmp”路径下。
kind: Deployment apiVersion: apps/v1 metadata: name: prometheus labels: app.kubernetes.io/component: prometheus app.kubernetes.io/instance: k8s app.kubernetes.io/name: prometheus app.kubernetes.io/part-of: kube-prometheus spec: replicas: 1 selector: matchLabels: app.kubernetes.io/component: prometheus # 架构中的组件 app.kubernetes.io/instance: k8s # 标识应用程序实例的唯一名称 app.kubernetes.io/name: prometheus # 应用程序的名称 app.kubernetes.io/part-of: kube-prometheus # 这是一个更高级别应用程序的名称 template: metadata: labels: app.kubernetes.io/component: prometheus app.kubernetes.io/instance: k8s app.kubernetes.io/name: prometheus app.kubernetes.io/part-of: kube-prometheus spec: volumes: # 在Volume中引用ConfigMap - name: prometheus-config configMap: name: prometheus-config defaultMode: 420 # ConfigMap卷中的所有文件默认设置为420 - name: kubeconfig configMap: name: kubeconfig defaultMode: 420 - name: prometheus-storage emptyDir: medium: LocalAuto sizeLimit: 10Gi containers: - name: prometheus image: 'swr.cn-north-7.myhuaweicloud.com/cci_k8s_gcr_io/...' args: # 传给可执行文件的参数(启动参数) - '--storage.tsdb.retention.time=12h' # 监控数据保留的时间 - '--config.file=/etc/prometheus/prometheus.yml' # 配置文件 - '--storage.tsdb.path=/prometheus/' # Prometheus写入数据库的地方 ports: - containerPort: 9090 protocol: TCP resources: limits: cpu: 500m memory: 1Gi requests: cpu: 500m memory: 1Gi volumeMounts: - name: prometheus-config mountPath: /etc/prometheus/ - name: kubeconfig mountPath: /etc/kube/ - name: prometheus-storage mountPath: /prometheus/ terminationMessagePath: /dev/termination-log # 表示容器的异常终止消息的路径 terminationMessagePolicy: File # 仅从终止消息文件中检索终止消息。 imagePullPolicy: Always restartPolicy: Always terminationGracePeriodSeconds: 30 # 优雅关闭的宽限期,即在收到停止请求后,有多少时间来进行资源释放或者做其它操作,如果到了最大时间还没有停止,会被强制结束。 dnsPolicy: ClusterFirst securityContext: {} schedulerName: default-scheduler strategy: type: RollingUpdate rollingUpdate: maxUnavailable: 25% maxSurge: 25% revisionHistoryLimit: 10 progressDeadlineSeconds: 600