部署 heapster 服务

k8s 扩展组件

  • kube-dns,为整个集群提供 DNS 服务
  • Ingress Controller,为服务提供外网入口,七层协议
  • Heapster,提供资源监控
  • Dashboard,提供 GUI
  • Federation,提供跨可用区的集群
  • Fluentd-elasticsearch,提供集群日志采集、存储和查询

部署 heapster 组件

创建两个 controller 文件,其中有三个服务,每个服务配了一个 svc。可通过 kubectl create -f . 批量创建。(注意提前 docker search 镜像,更新 tag 并 push 到本地镜像库中。)

# heapster-controller.yaml 
apiVersion: v1
kind: ReplicationController
metadata:
  labels:
    k8s-app: heapster
    name: heapster
    version: v6
  name: heapster
  namespace: kube-system
spec:
  replicas: 1
  selector:
    k8s-app: heapster
    version: v6
  template:
    metadata:
      labels:
        k8s-app: heapster
        version: v6
    spec:
      nodeSelector:
         kubernetes.io/hostname: k8s-master
      containers:
      - name: heapster
        image: 172.16.156.128:5000/kubernetes/heapster:canary # 镜像
        imagePullPolicy: IfNotPresent
        command:
        - /heapster
        - --source=kubernetes:http://172.16.156.128:8080?inClusterConfig=false
        - --sink=influxdb:http://monitoring-influxdb:8086

# heapster-service.yaml  
apiVersion: v1
kind: Service
metadata:
  labels:
    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-grafana-controller.yaml
apiVersion: v1
kind: ReplicationController
metadata:
  labels:
    name: influxGrafana
  name: influxdb-grafana
  namespace: kube-system
spec:
  replicas: 1
  selector:
    name: influxGrafana
  template:
    metadata:
      labels:
        name: influxGrafana
    spec:
      containers:
      - name: influxdb
        image: 172.16.156.128:5000/kubernetes/heapster_influxdb:v0.5 # 镜像
        imagePullPolicy: IfNotPresent
        volumeMounts:
        - mountPath: /data
          name: influxdb-storage
      - name: grafana
        imagePullPolicy: IfNotPresent
        image: 172.16.156.128:5000/kubernetes/heapster_grafana:v2.6.0 # 镜像
        env:
          - name: INFLUXDB_SERVICE_URL
            value: http://monitoring-influxdb:8086
            # The following env variables are required to make Grafana accessible via
            # the kubernetes api-server proxy. On production clusters, we recommend
            # removing these env variables, setup auth for grafana, and expose the grafana
            # service using a LoadBalancer or a public IP.
          - 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/proxy/namespaces/kube-system/services/monitoring-grafana/
        volumeMounts:
        - mountPath: /var
          name: grafana-storage
      nodeSelector:
         kubernetes.io/hostname: k8s-master
      volumes:
      - name: influxdb-storage
        emptyDir: {}
      - name: grafana-storage
        emptyDir: {}
# influxdb-service.yaml
apiVersion: v1
kind: Service
metadata:
  labels: null
  name: monitoring-influxdb
  namespace: kube-system
spec:
  ports:
  - name: http
    port: 8083
    targetPort: 8083
  - name: api
    port: 8086
    targetPort: 8086
  selector:
    name: influxGrafana
# grafana-service.yaml 
apiVersion: v1
kind: Service
metadata:
  labels:
    kubernetes.io/cluster-service: 'true'
    kubernetes.io/name: monitoring-grafana
  name: monitoring-grafana
  namespace: kube-system
spec:
  # In a production setup, we recommend accessing Grafana through an external Loadbalancer
  # or through a public IP. 
  # type: LoadBalancer
  ports:
  - port: 80
    targetPort: 3000
  selector:
    name: influxGrafana

启动 heapster 的时候总是报错,通过 kubectl logs 查看看到出现 The config file /etc/kubernetes/kubeconfig/kubeconfig does not exist 错误。网查是使用的版本太旧了,使用 v1.1.0 试试。(暂时失败,稍后再试)

你可能感兴趣的:(部署 heapster 服务)