kubernetes-dashboard
是官方提供的用户管理Kubernetes
集群可视化工具。通过这个后台可以可视化的创建应用。部署kubernetes-dashboard
其实和在kubernetes
部署其他的应用一样,创建dashboard
所需的Replication Controller
、Service
服务即可。
通过docker search
命令查看下有无kubernetes-dashboard
镜像:
> docker search Kubernetes-dashboard
上面图片展示了当前有的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
时会使用到这个镜像,在默认的配置文件中这个镜像的下载路径在国内有可能下载不下来镜像,从而导致pod
创建成功但是无法启动。所以这里需要修改一下pod-infrastructure
镜像的下载位置。具体的操作流程在这篇文章中:解决pod创建成功但未正常启动的问题:pod-infrastructure镜像下载失败。
直接下载:
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
这个配置文件中,重点需要修改的是以下几点配置:
spec.containers.image
: 该配置项配置的是kubernetes-dashboard
镜像拉取的地址,这里如果执行了上面下载镜像的操作,那么应该修改成本地Docker私有库
的镜像拉取地址:10.0.11.150:5000/kubernetes-dashboard-amd64
(这个是我本地私有库kubernetes-dashboard
镜像拉取地址)。
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
。
创建完kubernetes-dashboard
后,查看Pods
和Service
的详细信息:
// 查看所有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"
上图显示了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-dashboard
的Service
详细信息可以看到,该Service
绑定到了Node
节点的31897
端口上,从pod
详情信息中,我们知道这个kubernetes-dashboard Pod
部署在10.0.11.151
上。所以我们通过访问10.0.11.151:31897
就能看到Kubernetes的Web UI:
注:我们也可以通过 http://
这个链接访问dashboard Web UI。kubernetes-master
是指Kubernetes Master节点的aipserver服务地址,这里我的apiserver地址为:10.0.11.150:8080/ui
。