注意:两个node节点都需要下载此镜像,master节点不用,因为dashboard的pod会被master调度到两台node之一去创建,不会在master本地创建。
二.具体操作
以下操作全部在master节点执行:
1.编辑dashboard-controller.yaml,创建dashboard的pod
注意修改红色字体的部分!
vim dashboard-controller.yaml,内容如下:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: kubernetes-dashboard
namespace: kube-system
labels:
k8s-app: kubernetes-dashboard
kubernetes.io/cluster-service: "true"
spec:
selector:
matchLabels:
k8s-app: kubernetes-dashboard
template:
metadata:
labels:
k8s-app: kubernetes-dashboard
annotations:
scheduler.alpha.kubernetes.io/critical-pod: ''
scheduler.alpha.kubernetes.io/tolerations: '[{"key":"CriticalAddonsOnly", "operator":"Exists"}]'
spec:
containers:
name: kubernetes-dashboard
image: mritd/kubernetes-dashboard-amd64:v1.5.1
imagePullPolicy: IfNotPresent
resources:
limits:
cpu: 100m
memory: 50Mi
requests:
cpu: 100m
memory: 50Mi
ports:
--apiserver-host=http://10.0.2.90:8080
livenessProbe:
httpGet:
path: /
port: 9090
initialDelaySeconds: 30
timeoutSeconds: 30
containerPort: 9090
args:
红色字体解释:
mritd/kubernetes-dashboard-amd64:v1.5.1:dashboard的镜像,如果你的不是此镜像,请注意修改
--apiserver-host=http://10.0.2.90:8080,填写你master的apiserver地址,默认端口一般都是8080
===========================================================
OK,现在开始编辑dashboard-service.yaml,将dashboard的访问端口映射到两台node宿主机的端口,以便外部访问。
vim dashboard-service.yaml,内容如下:
apiVersion: v1
kind: Service
metadata:
name: kubernetes-dashboard
namespace: kube-system
labels:
k8s-app: kubernetes-dashboard
kubernetes.io/cluster-service: "true"
spec:
type: NodePort
selector:
k8s-app: kubernetes-dashboard
ports:
port: 80
targetPort: 9090
nodePort: 30003
红色字体解释:
port是指service的端口
targetport是指pod的端口
nodePort是指宿主机即node的端口,k8s外部就通过这个端口访问dashboard
创建dashboard
kubectl create -f dashboard-controller.yaml
结果显示:deployment "kubernetes-dashboard" created
kubectl create -f dashboard-service.yaml
结果显示:service "kubernetes-dashboard" created
查看创建结果:
[root@k8s-master yaml]# kubectl get pods --namespace=kube-system -o wide
NAME READY STATUS RESTARTS AGE IP NODE
kubernetes-dashboard-56bc76b6bb-b6kfx 1/1 Running 0 32s 172.18.0.194 node1
[root@k8s-master yaml]# kubectl get svc --namespace=kube-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes-dashboard NodePort 172.18.0.196 <none> 80:30003/TCP 13s
OK,创建成功,接下来就可以通过浏览器访问node节点(两个node任选一个都可以)的30003端口体验kubernetes-dashboard:
原文:http://blog.51cto.com/13557682/2122369