前情提要
以下所有操作均在单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 |
虚拟地址 |
Master端建立DashBoard
建立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
生成相关的POD
#顺序不能变!!!切记!!切记!!
[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
将POD划入指定命名空间
[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
此时,在浏览器访问某个node节点的30001端口即可
导致这个问题的根部原因就是缺少证书,某些浏览器会阻止不安全的访问
编写执行脚本进行证书自签
[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即可
把复制的token进行粘贴即可进入WEB页面
以上,就是整个K8S全部节点部署的配置过程~~~