官方的操作步骤是:https://github.com/kubernetes/dashboard
我自己的步骤是:
1,下载yaml文件
wget https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
2,编辑该yaml文件
# ------------------- 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: 8443
nodePort: 30001
selector:
k8s-app: kubernetes-dashboard
具体是:a,编辑spec.type;b,编辑spec.ports.nodePort
3,启动yaml文件中的多个资源项
kubectl create -f kubernetes-dashboard.yaml
4,检查service是否已经启动
kubectl get services -n kube-system | grep dashboard
5,接下来有两种方式可以验证,分别说下:
5.1,通过service查找IP+port,然后请求该端口即可。
查找命令:kubectl describe service kubernetes-dashboard -n kube-system
luwenwei@localhost:~$ kubectl describe service kubernetes-dashboard -n kube-system
Name: kubernetes-dashboard
Namespace: kube-system
Labels: k8s-app=kubernetes-dashboard
Annotations: <none>
Selector: k8s-app=kubernetes-dashboard
Type: NodePort
IP: 10.98.5.233
Port: <unset> /TCP
TargetPort: /TCP
NodePort: <unset> /TCP
Endpoints: 192.168.20.6:
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
访问请求:curl IP+port,IP是列出来的IP属性,port是列出来的port属性。
因为是443端口,可以推测是https请求。使用命令:curl https://aaa.com:443 --insecure
luwenwei@localhost:~$ curl https://10.98.5.233:443 --insecure
<!doctype html> <html ng-app="kubernetesDashboard"> <head> <meta charset="utf-8"> <title ng-controller="kdTitle as $ctrl" ng-bind="$ctrl.title()"></title> <link rel="icon" type="image/png" href="assets/images/kubernetes-logo.png"> <meta name="viewport" content="width=device-width"> <link rel="stylesheet" href="static/vendor.93db0a0d.css"> <link rel="stylesheet" href="static/app.ef45991b.css"> </head> <body ng-controller="kdMain as $ctrl"> <!--[if lt IE ]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser.
Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your
experience.</p>
<![endif]--> <kd-login layout="column" layout-fill ng-if="$ctrl.isLoginState()"> </kd-login> <kd-chrome layout="column" layout-fill ng-if="!$ctrl.isLoginState()"> </kd-chrome> <script src="static/vendor.bd425c26.js"></script> <script src="api/appConfig.json"></script> <script src="static/app.58f1fb61.js"></script> </body> </html>
如果输出的是以上的信息,说明dashboard已经安装成功,并可以访问。
5.2,通过proxy代理出一个machine端口,然后打开浏览器进行web方式访问(可以绕过5.1,直接使用5.2方式;也可以按序进行,先操作5.1,再操作5.2)
直接使用kubernetes proxy模式,穿透访问。
kubectl proxy --address='0.0.0.0' --accept-hosts='^*$'
打开浏览器:输入实体机IP(或者你用的是虚拟机,这里就是虚拟机的IP),端口是8001
luwenwei@localhost:~/k8s$ kubectl proxy --address='0.0.0.0' --accept-hosts='^*$'
Starting to serve on [::]:
输入后,返回这样的页面表示是成功了。
地址链接:http://192.168.52.128:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/#!/login
看到这个界面就已经成功一小半了,下来按部就班操作应该会简单很多。