以下所有操作均在单master群集已完成部署的情况下进行。
所有服务器均保证防火墙常闭,核心功能selinux关闭。
角色 | 地址 | 安装组件 |
---|---|---|
master | 192.168.142.220 | kube-apiserver kube-controller-manager kube-scheduler etcd |
master02 | 192.168.142.120 | kube-apiserver kube-controller-manager kube-scheduler |
node1 | 192.168.142.136 | kubelet kube-proxy docker flannel etcd |
node2 | 192.168.142.132 | kubelet kube-proxy docker flannel etcd |
nginx1 | 192.168.142.130 | nginx keepalived |
nginx2 | 192.168.142.140 | nginx keepalived |
VIP | 192.168.142.20 | 虚拟地址 |
建立dashboard工作目录
#在master上进行操作
[root@master ~]# cd /k8s/
#将需要上传的页面文件到此文件夹下
[root@master k8s]# mkdir dashboard
“dashboard-rbac” 授权许可连接APIserver
“dashboard-secret” 进行加密配置
“dashboard-configmap” dashboard配置文件
“dashboard-controller” 应用配置
“dashboard-service” 用于发布应用
上面四个YAML文件从GITHUB上进行下载,地址:https://github.com/kubernetes/kubernetes/tree/master/cluster/addons/dashboard
#顺序不能变!!!切记!!切记!!
[root@master dashboard]# kubectl create -f dashboard-rbac.yaml
[root@master dashboard]# kubectl create -f dashboard-secret.yaml
[root@master dashboard]# kubectl create -f dashboard-configmap.yaml
[root@master dashboard]# kubectl create -f dashboard-controller.yaml
[root@master dashboard]# kubectl create -f dashboard-service.yaml
[root@master dashboard]# kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
kubernetes-dashboard-65f974f565-d2wgw 1/1 Running 2 90s
#查看详细信息
[root@master dashboard]# kubectl get pods,svc -n kube-system
NAME READY STATUS RESTARTS AGE
pod/kubernetes-dashboard-65f974f565-d2wgw 1/1 Running 2 116s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes-dashboard NodePort 10.0.0.109 <none> 443:30001/TCP 112s
编写执行脚本进行证书自签
[root@master01 dashboard]# bash dashboard.sh /root/k8s/apiserver/
##脚本手工进行编写
#!/bin/bash
#DashBoard用证书
#
cat > dashboard-csr.json <<EOF
{
"CN": "Dashboard",
"hosts": [],
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"L": "BeiJing",
"ST": "BeiJing"
}
]
}
EOF
K8S_CA=$1
cfssl gencert -ca=$K8S_CA/ca.pem -ca-key=$K8S_CA/ca-key.pem -config=$K8S_CA/ca-config.json -profile=kubernetes dashboard-csr.json | cfssljson -bare dashboard
kubectl delete secret kubernetes-dashboard-certs -n kube-system
kubectl create secret generic kubernetes-dashboard-certs --from-file=./ -n kube-system
#重新应用自签的证书
[root@master01 dashboard]# vim dashboard-controller.yaml
args:
# PLATFORM-SPECIFIC ARGS HERE
- --auto-generate-certificates
- --tls-key-file=dashboard-key.pem
- --tls-cert-file=dashboard.pem ##添加最后两行
#进行重新部署
[root@master01 dashboard]# kubectl apply -f dashboard-controller.yaml
#生成令牌
[root@master01 dashboard]# kubectl create -f k8s-admin.yaml
#将令牌进行保存
[root@master01 dashboard]# kubectl get secret -n kube-system
NAME TYPE DATA AGE
dashboard-admin-token-klr2w kubernetes.io/service-account-token 3 74s
default-token-68xvt kubernetes.io/service-account-token 3 54m
kubernetes-dashboard-certs Opaque 10 11m
kubernetes-dashboard-key-holder Opaque 2 23m
kubernetes-dashboard-token-drsc7 kubernetes.io/service-account-token 3 23m
#查看保存的令牌
[root@master01 dashboard]# kubectl describe secret dashboard-admin-token-klr2w -n kube-system
##复制token即可
K8S多master部署三:部署DashBoard-UI界面
原文:https://blog.51cto.com/14484404/2469979