您好,登錄后才能下訂單哦!
以下所有操作均在單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即可
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。