kubernets monitoring

Weave Scope container map
 
Kubernetes create and deploy a cluster container applications only the first step. Once the cluster up and running, we need to ensure normal with all the necessary components in place and perform their duties and have sufficient resources to meet the needs of the application. Kubernetes is a complex system, operation and maintenance team need to have tools to help them learn real-time status of the cluster, and provide timely and accurate data to support troubleshooting.
 
Weave Scope is Docker and Kubernetes visual monitoring tool . Scope provides a top-down complete view of infrastructure and applications for clusters, users can easily containers distributed applications for real-time monitoring and problem diagnosis.
 
Weave Scope of the biggest feature is the Docker container will automatically generate a map, so that we can intuitively understand, monitor, and control the vessel . Less than a thousand words a picture, to feel it.
 
 

 

 
 
Weave Scope deployment
 
1) proceed to the next kubernetes scope.yml directory to find the file.
[to set a root @ cicd kubernetes] # the ls 
: bash ca harbor offline-installer-v1. 4.0 .tgz imagetargz kube-yunwei 197 targz sock shop 
bin catargz image k8s197targz scopeyaml

 

2) Create a weave namespace

[root@cicd kubernetes]# kubectl create namespace weave

2)安装scope,执行如下命令:
#kubectl apply -f scope.yaml
 
 
部署成功后,有如下相关组件:
[root@cicd kubernetes]# kubectl get pod -n weave 
NAME                               READY     STATUS    RESTARTS   AGE
weave-scope-agent-4xw7b            1/1       Running   0          2h
weave-scope-agent-cll6f            1/1       Running   0          2h
weave-scope-agent-nfl8c            1/1       Running   0          2h
weave-scope-app-5969c9bc78-fmm4s   1/1       Running   0          2h
[root@cicd kubernetes]# kubectl get svc -n weave 
NAME              TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
weave-scope-app   NodePort   10.68.210.240   <none>        80:33274/TCP   2h

 注意port端口号,用来浏览器访问。

  1. DaemonSet weave-scope-agent,集群每个节点上都会运行的 scope agent 程序,负责收集数据。
  2. Deployment weave-scope-app,scope 应用,从 agent 获取数据,通过 Web UI 展示并与用户交互。
  3. Service weave-scope-app,默认是 ClusterIP 类型,为了方便已通过 kubectl edit 修改为 NodePort
 
使用weavescope
 
登陆weavescope
浏览器访问 http://ip:33274/,Scope 默认显示当前所有的Controller(Deployment、DaemonSet 等)。
 

 

 

拓扑结构

Scope 会自动构建应用和集群的逻辑拓扑。比如点击顶部 PODS,会显示所有 Pod 以及 Pod 之间的依赖关系。

 

 同理点击 HOSTS,会显示各个节点之间的关系。
 
 

实时资源监控

可以在 Scope 中查看资源的 CPU 和内存使用情况。

 

支持图,表,柱状图显示
 
 

 

 

在线操作

Scope 还提供了便捷的在线操作功能,比如选中某个 Host,点击 >_ 按钮可以直接在浏览器中打开节点的命令行终端:
 
 
点击 Deployment 的 + 可以执行 Scale Up 操作:
 
可以 attach、restart、stop 容器,以及直接在 Scope 中排查问题:
 
详细信息包括这么几部分:
Status:CPU、内存的实时使用情况以及历史曲线。
INFO:容器 image、启动命令、状态、网络等信息。
以下几项需拉动滚动条查看。
 

PROCESSES:容器中运行的进程。

ENVIRONMENT VARIABLES:环境变量。
DOCKER LABELS:容器启动命令。
IMAGE:镜像详细信息。

在容器信息的上面还有一排操作按钮。

上图:左边框为atach按钮,右边框为exec按钮。一个是继续进程,一个是重开终端。

attach 到容器启动进程,相当于执行 docker container attach
打开shell,相当于执行docker container exec
重启容器,相当于执行 docker container restart
暂停容器,相当于执行 docker container pause
关闭容器,相当于执行 docker container stop
 

强大的搜索功能

Scope 支持关键字搜索和定位资源。
 
还可以进行条件搜索,比如查找和定位 cpu > 1% 的 Containers
 
Weave Scope 界面极其友好,操作简洁流畅。
 
 
 
 
二、用 Heapster 监控集群
Heapster介绍
 
Heapster 是 Kubernetes 原生的集群监控方案。Heapster 以 Pod 的形式运行,它会自动发现集群节点、从节点上的 Kubelet 获取监控数据。Kubelet 则是从节点上的 cAdvisor 收集数据。
 
Heapster 将数据按照 Pod 进行分组,将它们存储到预先配置的 backend 并进行可视化展示。Heapster 当前支持的 backend 有 InfluxDB(通过 Grafana 展示),Google Cloud Monitoring 等。Heapster 的整体架构如下图所示:
 
Heapster 本身是一个 Kubernetes 应用,部署方法很简单,之前章节中我们实践了由 Heapster、InfluxDB 和 Grafana 组成的监控方案。Kubelet 和 cAdvisor 是 Kubernetes 的自带组件,无需额外部署。
 
 

 部署步骤:

1)查看docker容器,并进入下载有ansible组件的容器。
[root@cicd kubernetes]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
415b685b8ace        1acb4fd5df5b        "/bin/sh"           4 days ago          Up 4 days                               keen_noyce
22c236dd2666        1acb4fd5df5b        "/bin/sh"           4 days ago          Up 4 days                               eloquent_bhabha
[root@cicd kubernetes]# docker exec -it 415b685b8ace /bin/sh

 

2)进入之前配置的/etc/ansible/manifest/heapster目录下,执行:
[root@cicd kubernetes]# docker exec -it 415b685b8ace /bin/sh
/ # cd /etc/ansible//etc/ansible # ls
01.prepare.yml      03.docker.yml       05.kube-node.yml    99.clean.yml        bin                 hosts               roles
02.etcd.yml         04.kube-master.yml  06.network.yml      ansible.cfg         example             manifests           tools
/etc/ansible # cd manifests/
/etc/ansible/manifests # ls
coredns    dashboard  efk        heapster   ingress    kubedns
/etc/ansible/manifests # cd heapster/
/etc/ansible/manifests/heapster # ls
grafana.yaml      heapster.yaml     influxdb-v1.1.1   influxdb-with-pv  influxdb.yaml
/etc/ansible/manifests/heapster # kubectl apply -f .
 
3)查看kube-system里的pod状态和service状态
/etc/ansible/manifests/heapster # kubectl get pod -n kube-system  -o wide
NAME                                       READY     STATUS    RESTARTS   AGE       IP               NODE
calico-kube-controllers-754c88ccc8-fm9kn   1/1       Running   0          4d        192.168.253.11   192.168.253.11
calico-node-62wzk                          2/2       Running   0          4d        192.168.253.14   192.168.253.14
calico-node-lszzj                          2/2       Running   6          4d        192.168.253.10   192.168.253.10
calico-node-nvtwd                          2/2       Running   0          4d        192.168.253.11   192.168.253.11
coredns-6ff7588dc6-62nnv                   1/1       Running   0          9h        172.20.104.44    192.168.253.11
coredns-6ff7588dc6-f6d4z                   1/1       Running   147        4d        172.20.104.1     192.168.253.11
heapster-7f8bf9bc46-l8qv5                  1/1       Running   0          3h        172.20.104.60    192.168.253.11
kubernetes-dashboard-545b66db97-mmt6p      1/1       Running   0          9h        172.20.104.43    192.168.253.11
monitoring-grafana-64747d765f-rb59j        1/1       Running   0          3h        172.20.135.23    192.168.253.10
monitoring-influxdb-565ff5f9b6-m99z8       1/1       Running   0          3h        172.20.135.21    192.168.253.10

/etc/ansible/manifests/heapster # kubectl get svc -n kube-system -o wide NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR coredns ClusterIP 10.68.0.2 <none> 53/UDP,53/TCP 4d k8s-app=coredns heapster ClusterIP 10.68.198.107 <none> 80/TCP 3h k8s-app=heapster kubernetes-dashboard NodePort 10.68.6.114 <none> 443:37107/TCP 4d k8s-app=kubernetes-dashboard monitoring-grafana ClusterIP 10.68.59.90 <none> 80/TCP 3h k8s-app=grafana monitoring-influxdb ClusterIP 10.68.11.36 <none> 8086/TCP 3h k8s-app=influxdb

 

4)生成集群链接地址
/etc/ansible/manifests/heapster # kubectl cluster-info
Kubernetes master is running at https://192.168.253.14:6443
CoreDNS is running at https://192.168.253.14:6443/api/v1/namespaces/kube-system/services/coredns:dns/proxy
kubernetes-dashboard is running at https://192.168.253.14:6443/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy
monitoring-grafana is running at https://192.168.253.14:6443/api/v1/namespaces/kube-system/services/monitoring-grafana/proxy

 

并打开浏览器访问。

 

 

 
 
 如果需要下载grafana
 

 

 

Guess you like

Origin www.cnblogs.com/zzzynx/p/11079041.html