kubernetes 资源监控

kubernetes 资源监控

kubernetes监控有多种方式,本章节介绍的为heapster独立版本,因为此种部署方式与dashborad结合比较紧密。

heapster独立服务部署

未部署监控前dashborad的node监控显示如下:

kubernetes 资源监控_第1张图片

heapster-controller.yaml:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: heapster-v1.2.0
  namespace: kube-system
  labels:
    k8s-app: heapster
    kubernetes.io/cluster-service: "true"
    version: v1.2.0
spec:
  replicas: 1
  selector:
    matchLabels:
      k8s-app: heapster
      version: v1.2.0
  template:
    metadata:
      labels:
        k8s-app: heapster
        version: v1.2.0
      annotations:
        scheduler.alpha.kubernetes.io/critical-pod: ''
        scheduler.alpha.kubernetes.io/tolerations: '[{"key":"CriticalAddonsOnly", "operator":"Exists"}]'
    spec:
      containers:
        - image: shenshouer/heapster:v1.2.0
          name: heapster
          livenessProbe:
            httpGet:
              path: /healthz
              port: 8082
              scheme: HTTP
            initialDelaySeconds: 180
            timeoutSeconds: 5
          resources:
            # keep request = limit to keep this container in guaranteed class
            limits:
              cpu: 80m
              memory: 200Mi
            requests:
              cpu: 80m
              memory: 200Mi
          command:
            - /heapster
            - --source=kubernetes.summary_api:''
        - image: shenshouer/addon-resizer:1.6
          name: heapster-nanny
          resources:
            limits:
              cpu: 50m
              memory: 92160Ki
            requests:
              cpu: 50m
              memory: 92160Ki
          env:
            - name: MY_POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: MY_POD_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          command:
            - /pod_nanny
            - --cpu=80m
            - --extra-cpu=0.5m
            - --memory=140Mi
            - --extra-memory=4Mi
            - --threshold=5
            - --deployment=heapster-v1.2.0
            - --container=heapster
            - --poll-period=300000
            - --estimator=exponential

heapster-service.yaml:

kind: Service
apiVersion: v1
metadata: 
  name: heapster
  namespace: kube-system
  labels: 
    kubernetes.io/cluster-service: "true"
    kubernetes.io/name: "Heapster"
spec: 
  ports: 
    - port: 80
      targetPort: 8082
  selector: 
    k8s-app: heapster

将如上两个文件放置到heapster/文件夹中执行如下命令:

sope-MacBookPro:heapster sope$ kubectl create -f ./
deployment "heapster-v1.2.0" created
service "heapster" created

检查服务启动情况:

# 检查heapster的pod启动情况
sope-MacBookPro:heapster sope$ kubectl --namespace kube-system get po -o wide
NAME                                READY     STATUS    RESTARTS   AGE       IP             NODE
heapster-v1.2.0-3541267077-9txto    2/2       Running   0          1m        10.244.160.4   172.19.8.103
kube-dns-v20-9oplg                  3/3       Running   3          3d        10.244.160.3   172.19.8.103
kubernetes-dashboard-v1.4.0-xslrc   1/1       Running   1          3d        10.244.232.2   172.19.8.102

# 检查rc启动情况:
sope-MacBookPro:heapster sope$ kubectl --namespace kube-system get rc
NAME                          DESIRED   CURRENT   READY     AGE
kube-dns-v20                  1         1         1         3d
kubernetes-dashboard-v1.4.0   1         1         1         3d

# 检查svc启动情况:
sope-MacBookPro:heapster sope$ kubectl --namespace kube-system get svc
NAME                   CLUSTER-IP     EXTERNAL-IP   PORT(S)         AGE
heapster               10.100.0.34    <none>        80/TCP          2m
kube-dns               10.100.0.10    <none>        53/UDP,53/TCP   3d
kubernetes-dashboard   10.100.0.224   <none>        80/TCP          3d

# 查看集群信息:
sope-MacBookPro:heapster sope$ kubectl cluster-info
Kubernetes master is running at https://172.19.8.101:443
Heapster is running at https://172.19.8.101:443/api/v1/proxy/namespaces/kube-system/services/heapster
KubeDNS is running at https://172.19.8.101:443/api/v1/proxy/namespaces/kube-system/services/kube-dns
kubernetes-dashboard is running at https://172.19.8.101:443/api/v1/proxy/namespaces/kube-system/services/kubernetes-dashboard

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

查看Dashborad,有监控数据显示:

kubernetes 资源监控_第2张图片

pod 监控数据显示:

kubernetes 资源监控_第3张图片

你可能感兴趣的:(kubernetes,docker,go)