Kubernetes技术分析之监控


【编者的话】Docker的流行激活了一直不温不火的PaaS,随着而来的是各类Micro-PaaS的出现,Kubernetes是其中最具代表性的一员,它是Google多年大规模容器管理技术的开源版本。本系列文章将逐一分析Kubernetes,本文介绍了Kubernetes中2个主要的监控模块cAdvisor和Heapster 。

Kubernetes监控

监控是运维的根基,是非常重要的一环,对此Kubernete提供了平台本身以及应用的监控,下图是Kubernete中监控的逻辑设计图:
1.jpg

cAdvisor

监控agent, 在每个Kubernetes Node上都会运行cAdvisor 。cadvisor 会收集本机以及容器的监控数据(CPU、 memory、filesystem and network usage statistics)。
在较新的Kubernetes版本里,cadvior功能已经被集成到了kubelet组件中。在Node节点上可以直接访问cAdvisor 的界面:
2.jpg

也可以调用cadvisor 的API接口,参考:
https://github.com/google/cadv ... pi.md

下面是cadvisor 一条记录,可以看到统计的监控数据范围:
{
        "timestamp": "2015-08-06T16:26:14.407749377+08:00",
        "cpu": {
            "usage": {
                "total": 9868208554,
                "per_cpu_usage": [9868208554],
                "user": 1850000000,
                "system": 280000000
            },
            "load_average": 0
        },
        "diskio": {
            "io_service_bytes": [{
                "major": 253,
                "minor": 7,
                "stats": {
                    "Async": 13946880,
                    "Read": 13946880,
                    "Sync": 0,
                    "Total": 13946880,
                    "Write": 0
                }
            }],
            "io_serviced": [{
                "major": 253,
                "minor": 7,
                "stats": {
                    "Async": 369,
                    "Read": 369,
                    "Sync": 0,
                    "Total": 369,
                    "Write": 0
                }
            }]
        },
        "memory": {
            "usage": 8548352,
            "working_set": 4067328,
            "container_data": {
                "pgfault": 6462,
                "pgmajfault": 132
            },
            "hierarchical_data": {
                "pgfault": 6462,
                "pgmajfault": 132
            }
        },
        "network": {
            "name": "",
            "rx_bytes": 0,
            "rx_packets": 0,
            "rx_errors": 0,
            "rx_dropped": 0,
            "tx_bytes": 0,
            "tx_packets": 0,
            "tx_errors": 0,
            "tx_dropped": 0
        },
        "task_stats": {
            "nr_sleeping": 0,
            "nr_running": 0,
            "nr_stopped": 0,
            "nr_uninterruptible": 0,
            "nr_io_wait": 0
        }
    },

Heapster

Heapster收集所有Kubernetes Node,然后汇总数据,然后可以导到第三方工具(如Influxdb)。

Heapster 可以以Pod的方式运行在Kubernetes平台里,也可以单独运行以standalone的方式。
使用Pod方式部署的话问题比较多,本文采用standalone方式部署。
$ docker run  -p 8082:8082 \
--add-host=node1:192.168.3.147 --add-host=node2:192.168.3.148 --add-host=node3:192.168.3.149 \
kubernetes/heapster:v0.15.0 \
--source=kubernetes:http://192.168.3.146:8080?inClusterConfig=false&useServiceAccount=false \
--sink=influxdb:http://10.254.209.104:8086 


source用于配置监控来源,它支持的参数:
  • inClusterConfig - Use kube config in service accounts associated with heapster's namesapce. (default: true)
  • kubeletPort - kubelet port to use (default: 10255)
  • kubeletHttps - whether to use https to connect to kubelets (default: false)
  • apiVersion - API version to use to talk to Kubernetes. Defaults to the version in kubeConfig.
  • insecure - whether to trust kubernetes certificates (default: false)
  • auth - client auth file to use. Set auth if the service accounts are not usable.
  • useServiceAccount - whether to use the service account token if one is mounted at/var/run/secrets/kubernetes.io/serviceaccount/token (default: false)


注意:--add-host主要是因为Heapster 会根据hostname去查询node的IP,参考:
https://github.com/GoogleCloud ... 62998

Heapster 运行后,可以在influxdb查询到数据,说明监控数据已经上报:
3.jpg

参考



==========================================================
作者简介
吴龙辉,现任网宿科技高级运营工程师,致力于云计算PaaS的研究和实践,活跃于CloudFoundry,Docker,Kubernetes等开源社区,贡献代码和撰写技术文档。 邮箱:wulh@chinanetcenter.com/wlh6666@qq.com

2 个评论

都是。。。我们玩剩下的- -
你就不该剩下,他们就没的玩了

要回复文章请先登录注册