prometheus监控使用(按照文档步调就可以利用乐成)。
文档分别坐了使用k8s集群摆设docker 跑prometheus监控。(后期如果有时间会做一个监控pod的文档)
特别说明:此情况要提前摆设好k8s。
1、prometheus 作为监控k8s的最佳选择在这里做一个在k8s摆设prometheus文档供各人参考。
#私自转载请接洽博主否则肯定追究版权 下方有微信
系统情况:
IP节点名称(不是主机名)192.168.182.150k8s-master192.168.182.151k8s-node2192.168.182.152k8s-node2192.168.182.153docker堆栈1、在docker堆栈内里先拉取prometheus images(直接使用k8s拉取因为网络问题可以说根本是失败的)。
docker堆栈执行
- docker pull prom/prometheus:v2.2.1 docker tag prom/prometheus:v2.2.1 192.168.182.153:5000/prom/prometheus:v2.2.1###为prometheus:v2.2.1 images 打一个标签docker push 192.168.182.153:5000/prom/prometheus:v2.2.1##上传打包后的prometheus:v2.2.1镜像
复制代码 2、使用k8s创建prometheus 容器设置。
k8s-master执行
- 创建文件prometheus-config.yml(如果是实验情况目次无所谓)apiVersion: v1kind: ConfigMapmetadata: name: prometheus-configdata: prometheus.yml: | global: scrape_interval: 15s evaluation_interval: 15s scrape_configs: - job_name: 'prometheus' static_configs: - targets: ['localhost:9090']创建文件prometheus-deployment.yml(如果是实验情况目次无所谓)apiVersion: v1kind: "Service"metadata: name: prometheus labels: name: prometheusspec: ports: - name: prometheus protocol: TCP port: 9090 targetPort: 9090 selector: app: prometheus type: NodePort---apiVersion: extensions/v1beta1kind: Deploymentmetadata: labels: name: prometheus name: prometheusspec: replicas: 1 template: metadata: labels: app: prometheus spec: containers: - name: prometheus image: prom/prometheus:v2.2.1 command: - "/bin/prometheus" args: - "--config.file=/etc/prometheus/prometheus.yml" ports: - containerPort: 9090 protocol: TCP volumeMounts: - mountPath: "/etc/prometheus" name: prometheus-config volumes: - name: prometheus-config configMap: name: prometheus-config
复制代码 3、使用k8s下发任务。
k8s-master执行
- kubectl create -f prometheus-config.ymlkubeckubectl create -f prometheus-deployment.yml
复制代码 4、检察任务进度。
k8s-master执行
- [root@master prometheus]# kubectl get pods ##如果下方创建失败可以根据NAME名称检察日志NAME READY STATUS RESTARTS AGEnginx-3121059884-lx6qc 1/1 Running 0 1hnginx-3121059884-n6bdl 1/1 Running 0 1hnginx-3121059884-n9pxz 1/1 Running 1 4hprometheus-3596598276-5wrkl 1/1 Running 0 1h
复制代码 5、检察失败日志(我上面是乐成后的所以状态是Running)各人可以看我的报错有多次镜像拉取失败。
k8s-master执行
- kubectl describe pod prometheus-3596598276-5wrklName: prometheus-3596598276-5wrklNamespace: defaultNode: node-1/192.168.182.151Start Time: Fri, 01 Jan 2021 21:39:02 +0800Labels: app=prometheus pod-template-hash=3596598276Status: RunningIP: 10.10.17.5Controllers: ReplicaSet/prometheus-3596598276Containers: prometheus: Container ID: docker://d2887dbb516b7415f0ddf1ee1c8fbf0b389db935e361c6108c44a9b52bb6ef29 Image: prom/prometheus:v2.2.1 Image ID: docker-pullable://192.168.182.153:5000/prom/prometheus@sha256:b0912ab008c270be88f6e81d3df6dfd24b7c1f9b4aacbffa70abe2a382152223 Port: 9090/TCP Command: /bin/prometheus Args: --config.file=/etc/prometheus/prometheus.yml State: Running Started: Fri, 01 Jan 2021 22:24:25 +0800 Ready: True Restart Count: 0 Volume Mounts: /etc/prometheus from prometheus-config (rw) Environment Variables: Conditions: Type Status Initialized True Ready True PodScheduled True Volumes: prometheus-config: Type: ConfigMap (a volume populated by a ConfigMap) Name: prometheus-configQoS Class: BestEffortTolerations: Events: FirstSeen LastSeen Count From SubObjectPath Type Reason Message --------- -------- ----- ---- ------------- -------- ------ ------- 1h 58m 9 {default-scheduler } Warning FailedScheduling no nodes available to schedule pods 57m 57m 6 {default-scheduler } Warning FailedScheduling no nodes available to schedule pods 56m 56m 1 {default-scheduler } Normal Scheduled Successfully assigned prometheus-3596598276-5wrkl to node-1 56m 44m 14 {kubelet node-1} Warning FailedMount MountVolume.SetUp failed for volume "kubernetes.io/configmap/0a83b05e-4c34-11eb-ae3b-000c29fd225f-prometheus-config" (spec.Name: "prometheus-config") pod "0a83b05e-4c34-11eb-ae3b-000c29fd225f" (UID: "0a83b05e-4c34-11eb-ae3b-000c29fd225f") with: configmaps "prometheus-config" not found 54m 43m 6 {kubelet node-1} Warning FailedMount Unable to mount volumes for pod "prometheus-3596598276-5wrkl_default(0a83b05e-4c34-11eb-ae3b-000c29fd225f)": timeout expired waiting for volumes to attach/mount for pod "default"/"prometheus-3596598276-5wrkl". list of unattached/unmounted volumes=[prometheus-config] 54m 43m 6 {kubelet node-1} Warning FailedSync Error syncing pod, skipping: timeout expired waiting for volumes to attach/mount for pod "default"/"prometheus-3596598276-5wrkl". list of unattached/unmounted volumes=[prometheus-config] 32m 32m 1 {kubelet node-1} spec.containers{prometheus} Normal BackOff Back-off pulling image "prom/prometheus:v2.2.1" 32m 32m 1 {kubelet node-1} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "prometheus" with ImagePullBackOff: "Back-off pulling image "prom/prometheus:v2.2.1"" 32m 14m 2 {kubelet node-1} spec.containers{prometheus} Warning Failed Failed to pull image "prom/prometheus:v2.2.1": net/http: request canceled 32m 14m 2 {kubelet node-1} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "prometheus" with ErrImagePull: "net/http: request canceled" 42m 14m 3 {kubelet node-1} spec.containers{prometheus} Normal Pulling pulling image "prom/prometheus:v2.2.1" 11m 11m 1 {kubelet node-1} spec.containers{prometheus} Normal Pulled Successfully pulled image "prom/prometheus:v2.2.1" 42m 11m 2 {kubelet node-1} Warning MissingClusterDNS kubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. Falling back to DNSDefault policy. 11m 11m 1 {kubelet node-1} spec.containers{prometheus} Normal Created Created container with docker id d2887dbb516b; Security:[seccomp=unconfined] 11m 11m 1 {kubelet node-1} spec.containers{prometheus} Normal Started Started container with docker id d2887dbb516b
复制代码 6、检察容器随机分配端口。
k8s-master执行
- [root@master prometheus]# kubectl get allNAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGEdeploy/nginx 3 3 3 3 4hdeploy/prometheus 1 1 1 1 1hNAME CLUSTER-IP EXTERNAL-IP PORT(S) AGEsvc/kubernetes 10.10.0.1 443/TCP 4hsvc/nginx 10.10.214.157 80:31882/TCP 4hsvc/prometheus 10.10.165.138 9090:32332/TCP 1h
复制代码 6、在web欣赏器打开。
来源:https://blog.csdn.net/zeorg/article/details/112075071
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |