heapster v1.5.4 +influxdb v1.5.2 +grafana v5.0.4 部署

版权声明:转载请注明出处,否则自行负责所有后果 https://blog.csdn.net/ljx1528/article/details/85426348

0、heapster安装包下载地址

https://github.com/kubernetes-retired/heapster/releases
#进入/root/heapster-1.5.4/deploy/kube-config/influxdb修改yaml文件镜像地址
[root@k8s_master influxdb]# ll /root/heapster-1.5.4/deploy/kube-config/influxdb
总用量 12
-rw-rw-r-- 1 root root 2290 7月  26 21:24 grafana.yaml
-rw-rw-r-- 1 root root 1114 7月  26 21:24 heapster.yaml
-rw-rw-r-- 1 root root  974 7月  26 21:24 influxdb.yaml

1、heapster-deployment.yaml 文件内容如下

[root@k8s_master ]# cat heapster-deployment.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:
      containers:
      - name: heapster
        image: registry.cn-hangzhou.aliyuncs.com/google_containers/heapster-amd64:v1.5.4
        imagePullPolicy: IfNotPresent
        command:
        - /heapster
        - --source=kubernetes:http://192.168.1.203:8080?inClusterConfig=false&kubeletHttps=true&kubeletPort=10250&useServiceAccount=true&auth= 
        - --sink=influxdb:http://monitoring-influxdb:8086
---
apiVersion: v1
kind: Service
metadata:
  labels:
    task: monitoring
    # For use as a Cluster add-on (https://github.com/kubernetes/kubernetes/tree/master/cluster/addons)
    # If you are NOT using this as an addon, you should comment out this line.
    kubernetes.io/cluster-service: 'true'
    kubernetes.io/name: Heapster
  name: heapster
  namespace: kube-system
spec:
  type: NodePort
  ports:
  - port: 80
    targetPort: 8082
    nodePort: 30010
  selector:
    k8s-app: heapster

2、influxdb-deployment.yaml 文件内容如下

[root@k8s_master ]# cat influxdb-deployment.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: registry.cn-hangzhou.aliyuncs.com/google_containers/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
    # For use as a Cluster add-on (https://github.com/kubernetes/kubernetes/tree/master/cluster/addons)
    # If you are NOT using this as an addon, you should comment out this line.
    kubernetes.io/cluster-service: 'true'
    kubernetes.io/name: monitoring-influxdb
  name: monitoring-influxdb
  namespace: kube-system
spec:
  ports:
  - name: http
    port: 8083
    targetPort: 8083
  - name: api
    port: 8086
    targetPort: 8086
  selector:
    k8s-app: influxdb
  externalIPs:
    - 192.168.1.203

3、grafana-deployment.yaml 文件内容如下

[root@k8s_master ]# cat grafana-deployment.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: registry.cn-hangzhou.aliyuncs.com/google_containers/heapster-grafana-amd64:v5.0.4
        ports:
          - containerPort: 3000
            protocol: TCP
        volumeMounts:
        - mountPath: /var
          name: grafana-storage
        env:
        - name: INFLUXDB_HOST
          value: monitoring-influxdb
        - name: GRAFANA_PORT
          value: "3000"
          # 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
          # If you're only using the API Server proxy, set this value instead:
          # value: /api/v1/proxy/namespaces/kube-system/services/monitoring-grafana/
          value: /
      volumes:
      - name: grafana-storage
        emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
  labels:
    # For use as a Cluster add-on (https://github.com/kubernetes/kubernetes/tree/master/cluster/addons)
    # If you are NOT using this as an addon, you should comment out this line.
    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
  # You could also use NodePort to expose the service at a randomly-generated port
  type: NodePort
  ports:
  - port: 3000
    targetPort: 3000
    protocol: TCP
    nodePort: 30011
  selector:
    k8s-app: grafana

4、创建对应的pod

kubectl create -f heapster-deployment.yaml
kubectl create -f influxdb-deployment.yaml
kubectl create -f grafana-deployment.yaml

5、检查pod是否启动正常

[root@k8s_master ~]# kubectl get pod -n kube-system
NAME                                    READY   STATUS    RESTARTS   AGE
coredns-67cb7b5f46-9lmrd                1/1     Running   0          2d4h
heapster-8488dbf48d-7db72               1/1     Running   0          2d3h
kubernetes-dashboard-574d4555f6-vfwxq   1/1     Running   0          85m
monitoring-grafana-6cf97675d9-wf8mf     1/1     Running   0          2d3h
monitoring-influxdb-66b55656cc-7th9r    1/1     Running   0          2d3h

[root@k8s_master ~]# kubectl get svc -n kube-system
NAME                   TYPE        CLUSTER-IP       EXTERNAL-IP     PORT(S)             AGE
coredns                ClusterIP   10.254.0.2       <none>          53/UDP,53/TCP       2d4h
heapster               NodePort    10.254.89.27     <none>          80:30010/TCP        2d3h
kubernetes-dashboard   NodePort    10.254.56.244    <none>          443:37897/TCP       86m
monitoring-grafana     NodePort    10.254.100.97    <none>          3000:30011/TCP      2d3h
monitoring-influxdb    ClusterIP   10.254.234.159   192.168.1.203   8083/TCP,8086/TCP   2d3h

6、如果heapster报错,需要执行以下文件内容

6.1、解决方法1

[root@k8s_master jiankong]# cat heapster-clusterrole.yaml 
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  annotations:
    rbac.authorization.kubernetes.io/autoupdate: "true"
  creationTimestamp: 2018-12-28T09:42:03Z
  labels:
    kubernetes.io/bootstrapping: rbac-defaults
  name: system:heapster
  resourceVersion: "50"
  selfLink: /apis/rbac.authorization.k8s.io/v1/clusterroles/system%3Aheapster
  uid: d4ca1c67-0a84-11e9-920e-fa163e958cc7
rules:
- apiGroups:
  - ""
  resources:
  - events
  - namespaces
  - nodes
  - pods
  - nodes/stats
  verbs:
  - create
  - get
  - list
  - watch
- apiGroups:
  - extensions
  resources:
  - deployments
  verbs:
  - get
  - list
  - watch

# 执行以下命令
kubectl create -f heapster-clusterrole.yaml 

6.2、解决方法2

[root@k8s_master rbac]# cat 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

---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: heapster-kubelet-api
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: system:kubelet-api-admin
subjects:
- kind: ServiceAccount
  name: heapster
  namespace: kube-system
  
#执行此yaml文件解决权限问题
[root@k8s_master ~]# kubectl create -f heapster-rbac.yaml 

有兴趣的朋友可以扫码拉群一起探讨k8s的更多问题
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/ljx1528/article/details/85426348