kubernetes-dashboard安装介绍(备忘)

可能的坑

安装kubernetes-dashboard主要遇到2个问题:

  1. 需要先安装heapster
  2. 账号验证问题
  3. 导出本机端口

安装 heapster

  1. 下载 heapster-controller.yaml

    curl -o heapster-controller.yaml https://github.com/kubernetes/heapster/blob/master/deploy/kube-config/standalone/heapster-controller.yaml
  2. 将 heapster-controller.yaml 修改成如下:

    apiVersion: v1
    kind: ServiceAccount
    metadata:
      labels:
        k8s-app: heapster
      name: heapster
      namespace: kube-system
    
    ---
    apiVersion: rbac.authorization.k8s.io/v1beta1
    kind: ClusterRoleBinding
    metadata:
      name: heapster
      labels:
        k8s-app: heapster
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: ClusterRole
      name: cluster-admin
    subjects:
      - kind: ServiceAccount
        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: k8s.gcr.io/heapster-amd64:v1.5.3
            imagePullPolicy: IfNotPresent
            command:
            - /heapster
    
            - --source=kubernetes:https://kubernetes.default
    ---
    
    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:
      ports:
      - port: 80
        targetPort: 8082
      selector:
        k8s-app: heapster

    主要修改 ServiceAccount 内容

  3. 开启 heapster

    kubectl create -f heapster-controller.yaml
    kubectl get all -l k8s-app=heapster --all-namespaces

安装 dashboard

  1. 下载 kubernetes-dashboard.yaml

    curl -o kubernetes-dashboard.yaml https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
  2. 将 kubernetes-dashboard.yaml 修改成如下:

     # Copyright 2017 The Kubernetes Authors.
     #
     # Licensed under the Apache License, Version 2.0 (the "License");
     # you may not use this file except in compliance with the License.
     # You may obtain a copy of the License at
     #
     #     http://www.apache.org/licenses/LICENSE-2.0
     #
     # Unless required by applicable law or agreed to in writing, software
     # distributed under the License is distributed on an "AS IS" BASIS,
     # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     # See the License for the specific language governing permissions and
     # limitations under the License.
    
     # Configuration to deploy release version of the Dashboard UI compatible with
     # Kubernetes 1.8.
     #
     # Example usage: kubectl create -f <this_file>
    
     # ------------------- Dashboard Service Account ------------------- #
    apiVersion: v1
    kind: ServiceAccount
    metadata:
      labels:
        k8s-app: kubernetes-dashboard
      name: kubernetes-dashboard
      namespace: kube-system
    
    ---
     # ------------------- Dashboard Role & Role Binding ------------------- #
    apiVersion: rbac.authorization.k8s.io/v1beta1
    kind: ClusterRoleBinding
    metadata:
      name: kubernetes-dashboard
      labels:
        k8s-app: kubernetes-dashboard
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: ClusterRole
      name: cluster-admin
    subjects:
      - kind: ServiceAccount
        name: kubernetes-dashboard
        namespace: kube-system
    
    ---
     # ------------------- Dashboard Deployment ------------------- #
    kind: Deployment
    apiVersion: apps/v1beta2
    metadata:
      labels:
        k8s-app: kubernetes-dashboard
      name: kubernetes-dashboard
      namespace: kube-system
    spec:
      replicas: 1
      revisionHistoryLimit: 10
      selector:
        matchLabels:
          k8s-app: kubernetes-dashboard
      template:
        metadata:
          labels:
            k8s-app: kubernetes-dashboard
        spec:
          containers:
          - name: kubernetes-dashboard
            image: k8s.gcr.io/kubernetes-dashboard-amd64:v1.8.3
            ports:
            - containerPort: 9090
              protocol: TCP
            args:
              # - --auto-generate-certificates
              # Uncomment the following line to manually specify Kubernetes API server Host
              # If not specified, Dashboard will attempt to auto discover the API server and connect
              # to it. Uncomment only if the default does not work.
              # - --apiserver-host=http://my-address:port
              - --heapster-host=http://heapster
            livenessProbe:
              httpGet:
                path: /
                port: 9090
              initialDelaySeconds: 30
              timeoutSeconds: 30
          serviceAccountName: kubernetes-dashboard
          # Comment the following tolerations if Dashboard must not be deployed on master
          tolerations:
          - key: node-role.kubernetes.io/master
            effect: NoSchedule
    
    ---
     # ------------------- Dashboard Service ------------------- #
    kind: Service
    apiVersion: v1
    metadata:
      labels:
        k8s-app: kubernetes-dashboard
      name: kubernetes-dashboard
      namespace: kube-system
    spec:
      type: NodePort
      ports:
        - port: 443
          targetPort: 9090
          nodePort: 30002
      selector:
        k8s-app: kubernetes-dashboard

    主要修改了 ServiceAccount 信息、导出NodePort、修改8443为9090

  3. 开启 dashboard

    kubectl create -f kubernetes-dashboard.yaml
  4. 验证

    curl http://localhost:30002

    或者IE中访问: htttp://your-ip:30002

  5. 结果图:
    这里写图片描述

以上

猜你喜欢

转载自blog.csdn.net/u013272009/article/details/80656435