这篇文章给大家分享的是有关kubernetes中dashboard如何安装的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
wget -O k8s-dashboard.yaml https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.5/aio/deploy/recommended.yaml
kind: Service
apiVersion: v1
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kubernetes-dashboard
spec:
type: NodePort
ports:
- port: 443
targetPort: 8443
nodePort: 30001
selector:
k8s-app: kubernetes-dashboard
自定义https (https://github.com/kubernetes/dashboard/blob/master/docs/user/installation.md)
# 参考https://my.oschina.net/u/160697/blog/4602174
cd ~
curl -s https://get.acme.sh | sh
# 设置别名方便使用命令
alias acme.sh=~/.acme.sh/acme.sh
# 导出aliyun key, 需加入到环境变量中
export Ali_Key="xxxx"
export Ali_Secret="xxxx"
# 申请证书
acme.sh --issue --dns dns_ali -d k8s.your_domain.com
# 导出证书使用
mkdir certs
acme.sh --installcert -d k8s.your_domain.com \
--key-file ~/certs/tls.key \
--fullchain-file ~/certs/tls.crt
删除k8s-dashboard.yaml中的以下
# apiVersion: v1
# kind: Secret
# metadata:
# labels:
# k8s-app: kubernetes-dashboard
# name: kubernetes-dashboard-certs
# namespace: kubernetes-dashboard
# type: Opaque
先创建certs
kubectl create ns kubernetes-dashboard
kubectl create secret generic kubernetes-dashboard-certs --from-file=$HOME/certs -n kubernetes-dashboard
Deployment的args增加key
args:
#--auto-generate-certificates
- --namespace=kubernetes-dashboard
- --token-ttl=43200
- --tls-cert-file=tls.crt
- --tls-key-file=tls.key
应用文件
kubectl apply -f k8s-dashboard.yaml
# 创建一个dashboard的管理用户
kubectl create serviceaccount dashboard-admin -n kube-system
# 将创建的dashboard用户绑定为管理用户
kubectl create clusterrolebinding dashboard-cluster-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin
# 通过kubectl get secrets -n kube-system | grep dashboard。获得你的key
DASH_TOKEN=$(kubectl get secrets -n kube-system dashboard-admin-token-你的key -o jsonpath={.data.
token} | base64 -d)
# 创建kubeconfig的登录文件
# your_name为ubuntu的用户名,根据情况修改
kubectl config set-cluster kubernets --server=192.168.1.30:6443 --kubeconfig=/home/your_name/.dashboard-admin.conf
kubectl config set-credentials dashboard-admin --token=${DASH_TOKEN} --kubeconfig=/home/your_name/.dashboard-admin.conf
kubectl config set-context dashboard-admin@kubernetes --cluster=kubernetes --user=dashboard-admin --kubeconfig=/home/your_name/.dashboard-admin.conf
kubectl config use-context dashboard-admin@kubernetes --kubeconfig=/home/your_name/.dashboard-admin.conf
最后把.dashboard-admin.conf拷到其它机器上,使用此文件可登录
安装cpu. 内存监控参考 https://my.oschina.net/u/160697/blog/write/3186880
感谢各位的阅读!关于“kubernetes中dashboard如何安装”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!