这篇文章整理来介绍一下使用kubelet中使用api来确认指标数据的方式,为后续使用metrics server/heapster/prometheus打下一点基础。
cadvisor在其他文章中已经早有介绍,现在已经成为kubelet的一部分,这篇文章也将演示一下如何使用api方式来访问cadvisor
可参看如下文章进行设定:
- https://liumiaocn.blog.csdn.net/article/details/88882893
[root@host131 kubernetes]# netstat -tunlp |grep kubelet
tcp 0 0 127.0.0.1:10248 0.0.0.0:* LISTEN 9028/kubelet
tcp 0 0 192.168.163.131:10250 0.0.0.0:* LISTEN 9028/kubelet
tcp 0 0 127.0.0.1:38593 0.0.0.0:* LISTEN 9028/kubelet
[root@host131 kubernetes]#
curl -s --cacert /etc/ssl/ca/ca.pem --cert /etc/ssl/ca/kubeadmin.pem --key /etc/ssl/ca/kubeadmin-key.pem https://192.168.163.131:10250/metrics
[root@host131 kubernetes]# curl -s --cacert /etc/ssl/ca/ca.pem --cert /etc/ssl/ca/kubeadmin.pem --key /etc/ssl/ca/kubeadmin-key.pem https://192.168.163.131:10250/metrics | head -n 10
# HELP apiserver_audit_event_total Counter of audit events generated and sent to the audit backend.
# TYPE apiserver_audit_event_total counter
apiserver_audit_event_total 0
# HELP apiserver_audit_requests_rejected_total Counter of apiserver requests rejected due to an error in audit logging backend.
# TYPE apiserver_audit_requests_rejected_total counter
apiserver_audit_requests_rejected_total 0
# HELP apiserver_client_certificate_expiration_seconds Distribution of the remaining lifetime on the certificate used to authenticate a request.
# TYPE apiserver_client_certificate_expiration_seconds histogram
apiserver_client_certificate_expiration_seconds_bucket{le="0"} 0
apiserver_client_certificate_expiration_seconds_bucket{le="21600"} 0
[root@host131 kubernetes]#
curl -s --cacert /etc/ssl/ca/ca.pem --cert /etc/ssl/ca/kubeadmin.pem --key /etc/ssl/ca/kubeadmin-key.pem https://192.168.163.131:10250/metrics/cadvisor
[root@host131 kubernetes]# curl -s --cacert /etc/ssl/ca/ca.pem --cert /etc/ssl/ca/kubeadmin.pem --key /etc/ssl/ca/kubeadmin-key.pem https://192.168.163.131:10250/metrics/cadvisor |head -n 10
# HELP cadvisor_version_info A metric with a constant '1' value labeled by kernel version, OS version, docker version, cadvisor version & cadvisor revision.
# TYPE cadvisor_version_info gauge
cadvisor_version_info{cadvisorRevision="",cadvisorVersion="",dockerVersion="17.03.2-ce",kernelVersion="3.10.0-957.el7.x86_64",osVersion="CentOS Linux 7 (Core)"} 1
# HELP container_cpu_load_average_10s Value of container cpu load average over the last 10 seconds.
# TYPE container_cpu_load_average_10s gauge
container_cpu_load_average_10s{container_name="",id="/",image="",name="",namespace="",pod_name=""} 0
container_cpu_load_average_10s{container_name="",id="/kube-proxy",image="",name="",namespace="",pod_name=""} 0
container_cpu_load_average_10s{container_name="",id="/kubepods",image="",name="",namespace="",pod_name=""} 0
container_cpu_load_average_10s{container_name="",id="/kubepods/besteffort",image="",name="",namespace="",pod_name=""} 0
container_cpu_load_average_10s{container_name="",id="/kubepods/besteffort/pod564c319b-525c-11e9-92c4-080027f8be6f",image="",name="",namespace="kube-system",pod_name="kubernetes-dashboard-57df4db6b-hn4jr"} 0
[root@host131 kubernetes]#
curl -s --cacert /etc/ssl/ca/ca.pem --cert /etc/ssl/ca/kubeadmin.pem --key /etc/ssl/ca/kubeadmin-key.pem https://192.168.163.131:10250/metrics/cadvisor
[root@host131 kubernetes]# curl -s --cacert /etc/ssl/ca/ca.pem --cert /etc/ssl/ca/kubeadmin.pem --key /etc/ssl/ca/kubeadmin-key.pem https://192.168.163.131:10250/stats/container/|head -n 10
{
"/": {
"name": "/",
"subcontainers": [
{
"name": "/kube-proxy"
},
{
"name": "/kubepods"
},
[root@host131 kubernetes]#
注意事项:
一般来说只要HTTPS的6443能通,kubelet设定正确的情况下,页面访问也没有问题,一键安装的脚本中缺省设置即可。客户端设定可参看: