Kubernetes dashboard1.5.2 Web UI搭建

kubernetes-dashboard是官方提供的用户管理Kubernetes集群可视化工具。通过这个后台可以可视化的创建应用。部署kubernetes-dashboard其实和在kubernetes部署其他的应用一样,创建dashboard所需的Replication ControllerService服务即可。

下载kubernetes-dashboard

通过docker search命令查看下有无kubernetes-dashboard镜像:

> docker search Kubernetes-dashboard

Kubernetes dashboard1.5.2 Web UI搭建_第1张图片

上面图片展示了当前有的kubernetes-dashboard镜像,我只截取了有下载量的这几个,这里我下载的是第一个下载量最大的。

下载好kubernetes-dashboard镜像之后,需要将镜像进行tag打标签,然后push到本地的私有库中。因为我们在部署kubernetes-dashboard时,会直接从本地私有库中获取镜像然后进行部署,这样操作速度快效果好出错少。

// 进行tag标记,其中10.0.11.150:5000是我本地私有库的地址端口
docker tag docker.io/mritd/kubernetes-dashboard-amd64:latest 10.0.11.150:5000/kubernetes-dashboard-amd64

// push上传到本地私有库
docker push 10.0.11.150:5000/kubernetes-dashboard-amd64:latest

下载pod-infrastructure镜像

在创建启动一个pod时会使用到这个镜像,在默认的配置文件中这个镜像的下载路径在国内有可能下载不下来镜像,从而导致pod创建成功但是无法启动。所以这里需要修改一下pod-infrastructure镜像的下载位置。具体的操作流程在这篇文章中:解决pod创建成功但未正常启动的问题:pod-infrastructure镜像下载失败。

编写并执行yaml文件

直接下载:

wget  https://rawgit.com/kubernetes/dashboard/master/src/deploy/kubernetes-dashboard.yaml

本地编写:

# Copyright 2015 Google Inc. All Rights Reserved. 
# 
# 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. 
# 
# Example usage: kubectl create -f  

kind: Deployment  
apiVersion: extensions/v1beta1
metadata:  
  labels:  
    app: kubernetes-dashboard  
    version: latest 
  name: kubernetes-dashboard  
  namespace: kube-system  
spec:  
  replicas: 1  
  selector:  
    matchLabels:  
      app: kubernetes-dashboard  
  template:  
    metadata:  
      labels:  
        app: kubernetes-dashboard  
      # Comment the following annotation if Dashboard must not be deployed on master
      annotations:
        scheduler.alpha.kubernetes.io/tolerations: |
          [
            {
              "key": "dedicated",
              "operator": "Equal",
              "value": "master",
              "effect": "NoSchedule"
            }
          ]
    spec:  
      containers:  
      - name: kubernetes-dashboard  
        image: 10.0.11.150:5000/kubernetes-dashboard-amd64  
        imagePullPolicy: Always
        ports:  
        - containerPort: 9090  
          protocol: TCP  
        args:  
          # 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=10.0.11.150:8080  
        livenessProbe:  
          httpGet:  
            path: /  
            port: 9090  
          initialDelaySeconds: 30  
          timeoutSeconds: 30  
---  
kind: Service  
apiVersion: v1  
metadata:  
  labels:  
    app: kubernetes-dashboard  
  name: kubernetes-dashboard  
  namespace: kube-system  
spec:  
  type: NodePort  
  ports:  
  - port: 80  
    targetPort: 9090  
  selector:  
    app: kubernetes-dashboard

这个配置文件中,重点需要修改的是以下几点配置:

  1. spec.containers.image : 该配置项配置的是kubernetes-dashboard镜像拉取的地址,这里如果执行了上面下载镜像的操作,那么应该修改成本地Docker私有库的镜像拉取地址:10.0.11.150:5000/kubernetes-dashboard-amd64(这个是我本地私有库kubernetes-dashboard镜像拉取地址)。

  2. apiserver-host : 该参数配置的是Kubernetes Master节点的aipserver服务地址。可查看/etc/kubernetes/config配置文件中的KUBE_MASTER配置项获得。

编写完kubernetes-dashboard.yaml配置文件之后,将该文件保存到Kubernetes Master节点上,然后执行下面这条命令:

kubectl create -f kubernetes-dashboard.yaml

该命令是通过kubernetes-dashboard.yaml配置文件创建并启动了一个pod

dashboard信息查看及管理

创建完kubernetes-dashboard后,查看PodsService的详细信息:

// 查看所有namespace下的pod信息。若没有携带--all-namespaces,则无法查看到dashboard的pod信息,
// 因为dashboard在kube-system这个namespace下。可查看配置文件。

# kubectl get pods --all-namespaces

NAMESPACE     NAME                                    READY     STATUS    RESTARTS   AGE
kube-system   kubernetes-dashboard-4148467691-jlf9j   1/1       Running   0          14h

查看具体pod详情信息:

// kubernetes-dashboard-4148467691-jlf9j:pod name 
// --namespace="kube-system" : 指定namespace

# kubectl describe pods/kubernetes-dashboard-4148467691-jlf9j --namespace="kube-system"

Kubernetes dashboard1.5.2 Web UI搭建_第2张图片

上图显示了pods/kubernetes-dashboard-4148467691-jlf9j的详情信息。

查看kubernetes-dashboard Service详情信息:

# kubectl describe service/kubernetes-dashboard --namespace="kube-system"

Name:                   kubernetes-dashboard
Namespace:              kube-system
Labels:                 app=kubernetes-dashboard
Selector:               app=kubernetes-dashboard
Type:                   NodePort
IP:                     10.254.186.27
Port:                    80/TCP
NodePort:                31897/TCP
Endpoints:              10.1.96.2:9090
Session Affinity:       None

kubernetes-dashboardService详细信息可以看到,该Service绑定到了Node节点的31897端口上,从pod详情信息中,我们知道这个kubernetes-dashboard Pod部署在10.0.11.151上。所以我们通过访问10.0.11.151:31897就能看到Kubernetes的Web UI:

Kubernetes dashboard1.5.2 Web UI搭建_第3张图片

注:我们也可以通过 http:///ui这个链接访问dashboard Web UI。kubernetes-master是指Kubernetes Master节点的aipserver服务地址,这里我的apiserver地址为:10.0.11.150:8080/ui

你可能感兴趣的:(Docker)