阅读量:3
一、前置准备:确保已安装Kubernetes集群
在Ubuntu上安装Kubernetes Dashboard前,需先部署一个可用的Kubernetes集群(若未安装,可参考以下基础步骤):
- 安装Docker
更新系统包并添加Docker官方源,安装Docker CE:sudo apt-get update sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" sudo apt-get update sudo apt-get install -y docker-ce - 安装Kubernetes组件
添加Kubernetes软件源,安装kubelet、kubeadm、kubectl:curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list deb https://apt.kubernetes.io/ kubernetes-xenial main EOF sudo apt-get update sudo apt-get install -y kubelet kubeadm kubectl sudo apt-mark hold kubelet kubeadm kubectl # 锁定版本避免自动升级 - 初始化Kubernetes集群
使用kubeadm初始化Master节点(假设Pod网络CIDR为10.244.0.0/16):sudo kubeadm init --pod-network-cidr=10.244.0.0/16 - 配置kubectl
将集群配置复制到当前用户目录:mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config - 安装网络插件
以Flannel为例,部署容器网络:kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
二、安装Kubernetes Dashboard
- 部署Dashboard
使用官方推荐的YAML文件部署Dashboard(最新版本可通过kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml调整版本):
验证Deployment状态:kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta8/aio/deploy/recommended.yamlkubectl get pods -n kubernetes-dashboard # 确保所有Pod状态为"Running"
三、配置访问权限
- 创建ServiceAccount
创建专用于Dashboard访问的ServiceAccount:kubectl create serviceaccount dashboard-admin -n kube-system - 绑定ClusterRole权限
为ServiceAccount绑定cluster-admin角色(最高权限,生产环境建议限制为必要权限):kubectl create clusterrolebinding dashboard-admin \ --clusterrole=cluster-admin \ --serviceaccount=kube-system:dashboard-admin
四、获取访问Token
- 生成Token
通过以下命令获取ServiceAccount对应的Token:输出中的kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep dashboard-admin | awk '{print $1}')token字段即为登录Dashboard所需的凭证。
五、访问Dashboard
- 启动本地代理
在Ubuntu服务器上启动kubectl proxy,创建本地到集群的安全通道:
代理默认监听kubectl proxylocalhost:8001。 - 通过浏览器访问
打开浏览器,输入以下URL(替换为服务器IP,若需外部访问需配置Ingress或NodePort):- 本地访问:
http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/ - 外部访问(需提前配置端口转发或Ingress):
http://<服务器IP>:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
- 本地访问:
- 登录Dashboard
在登录页面选择“Token”选项,粘贴之前获取的Token,即可登录Dashboard。
可选:配置外部访问(NodePort方式)
若需从外部网络访问Dashboard,可将Dashboard服务类型改为NodePort:
- 编辑服务配置:
kubectl -n kubernetes-dashboard edit service kubernetes-dashboard - 修改服务类型:
将type: ClusterIP改为type: NodePort,保存退出。 - 获取访问端口:
查看服务详情,获取分配的NodePort(如30454):kubectl -n kubernetes-dashboard get service kubernetes-dashboard - 访问Dashboard:
通过http://<服务器IP>:访问(如http://192.168.1.100:30454)。
以上就是关于“如何在Ubuntu上安装Kubernetes Dashboard”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm