kubernetes1.13.4集成安装heapster

基础环境

拥有一个完美运行的kubernetes1.13.4集群并已经部署过dashboard,可参考我的部署文章创建自己的集群。

NT:heapster在kubernetes1.8以后不被推荐了,转而推荐使用metrics-server

部署步骤

  1. 编写部署需要的yaml文件

    NT:下面的文件相较于官方文档有改动,解决了国内环境的镜像拉取问题,同时解决了几个小bug。大家可以对比参考。

    • grafana.yaml

      apiVersion: extensions/v1beta1
      kind: Deployment
      metadata:
        name: monitoring-grafana
        namespace: kube-system
      spec:
        replicas: 1
        template:
          metadata:
            labels:
              task: monitoring
              k8s-app: grafana
          spec:
            containers:
            - name: grafana
              image: docker.io/mirrorgooglecontainers/heapster-grafana-amd64:v5.0.4
              ports:
              - containerPort: 3000
                protocol: TCP
              volumeMounts:
              - mountPath: /etc/ssl/certs
                name: ca-certificates
                readOnly: true
              - mountPath: /var
                name: grafana-storage
              env:
              - name: INFLUXDB_HOST
                value: monitoring-influxdb
              - name: GF_SERVER_HTTP_PORT
                value: "3000"
              - name: GF_AUTH_BASIC_ENABLED
                value: "false"
              - name: GF_AUTH_ANONYMOUS_ENABLED
                value: "true"
              - name: GF_AUTH_ANONYMOUS_ORG_ROLE
                value: Admin
              - name: GF_SERVER_ROOT_URL
                value: /api/v1/namespaces/kube-system/services/monitoring-grafana/proxy
            volumes:
            - name: ca-certificates
              hostPath:
                path: /etc/ssl/certs
            - name: grafana-storage
              emptyDir: {}
      ---
      apiVersion: v1
      kind: Service
      metadata:
        labels:
          kubernetes.io/cluster-service: 'true'
          kubernetes.io/name: monitoring-grafana
        name: monitoring-grafana
        namespace: kube-system
      spec:
        type: NodePort
        ports:
        - port: 80
          targetPort: 3000
        selector:
          k8s-app: grafana
      
    • heapster-clusterrole.yaml

      apiVersion: rbac.authorization.k8s.io/v1
      kind: ClusterRole
      metadata:
        annotations:
          rbac.authorization.kubernetes.io/autoupdate: "true"
        labels:
          kubernetes.io/bootstrapping: rbac-defaults
        name: system:heapster
      rules:
      - apiGroups:
        - ""
        resources:
        - events
        - namespaces
        - nodes
        - pods
        - nodes/stats
        verbs:
        - create
        - get
        - list
        - watch
      - apiGroups:
        - extensions
        resources:
        - deployments
        verbs:
        - get
        - list
        - watch
      
    • heapster-rbac.yaml

      kind: ClusterRoleBinding
      apiVersion: rbac.authorization.k8s.io/v1beta1
      metadata:
        name: heapster
      roleRef:
        apiGroup: rbac.authorization.k8s.io
        kind: ClusterRole
        name: system:heapster
      subjects:
      - kind: ServiceAccount
        name: heapster
        namespace: kube-system
      
    • heapster.yaml

      apiVersion: v1
      kind: ServiceAccount
      metadata:
        name: heapster
        namespace: kube-system
      ---
      apiVersion: extensions/v1beta1
      kind: Deployment
      metadata:
        name: heapster
        namespace: kube-system
      spec:
        replicas: 1
        template:
          metadata:
            labels:
              task: monitoring
              k8s-app: heapster
          spec:
            serviceAccountName: heapster
            containers:
            - name: heapster
              image: docker.io/mirrorgooglecontainers/heapster-amd64:v1.5.4
              imagePullPolicy: IfNotPresent
              command:
              - /heapster
              - --source=kubernetes:https://kubernetes.default?useServiceAccount=true&kubeletHttps=true&kubeletPort=10250&insecure=true
              - --sink=influxdb:http://monitoring-influxdb.kube-system.svc:8086
      ---
      apiVersion: v1
      kind: Service
      metadata:
        labels:
          task: monitoring
          kubernetes.io/cluster-service: 'true'
          kubernetes.io/name: Heapster
        name: heapster
        namespace: kube-system
      spec:
        ports:
        - port: 80
          targetPort: 8082
        selector:
          k8s-app: heapster
      
    • influxdb.yaml

      apiVersion: extensions/v1beta1
      kind: Deployment
      metadata:
        name: monitoring-influxdb
        namespace: kube-system
      spec:
        replicas: 1
        template:
          metadata:
            labels:
              task: monitoring
              k8s-app: influxdb
          spec:
            containers:
            - name: influxdb
              image: docker.io/mirrorgooglecontainers/heapster-influxdb-amd64:v1.5.2
              volumeMounts:
              - mountPath: /data
                name: influxdb-storage
            volumes:
            - name: influxdb-storage
              emptyDir: {}
      ---
      apiVersion: v1
      kind: Service
      metadata:
        labels:
          task: monitoring
          kubernetes.io/cluster-service: 'true'
          kubernetes.io/name: monitoring-influxdb
        name: monitoring-influxdb
        namespace: kube-system
      spec:
        type: NodePort
        ports:
        - port: 8086
          targetPort: 8086
        selector:
          k8s-app: influxdb
      
      
  2. 执行命令完成部署

    $ ls
    grafana.yaml  heapster-clusterrole.yaml  heapster-rbac.yaml  heapster.yaml  influxdb.yaml
    
    $ kubectl create -f .
    
  3. 等待所有pod的状态达到running,登录dashboard就可以看到图形化界面了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值