实验 详解K8S的web界面部署以及解决谷歌浏览器无法访问的问题
目录一 K8S的web界面部署二 解决谷歌浏览器访问web界面问题一 K8S的web界面部署##在master01上操作##1. 创建dashborad工作目录[root@master01 ~]# cd /root/k8s/[root@master01 k8s]# mkdir dashboard[root@master01 k8s]# cd dashboard/[root@master01 das
·
一 K8S的web界面部署
##在master01上操作##
1. 创建dashborad工作目录
[root@master01 ~]# cd /root/k8s/
[root@master01 k8s]# mkdir dashboard
[root@master01 k8s]# cd dashboard/
[root@master01 dashboard]# rz -E ##传下好的yaml文件(https://github.com/kubernetes/kubernetes/tree/master/cluster/addons/dashboard)
rz waiting to receive.
[root@master01 dashboard]# ls
apiserver.sh dashboard-service.yaml kubeconfig
cfssl.sh etcd-cert kubernetes
controller-manager.sh etcd.sh kubernetes-server-linux-amd64.tar.gz
dashboard etcd-v3.3.10-linux-amd64 kubernetes-server-linux-amd64.tar.gz.0
dashboard-configmap.yaml etcd-v3.3.10-linux-amd64.tar.gz master.zip
dashboard-controller.yaml flannel-v0.10.0-linux-amd64.tar.gz scheduler.sh
dashboard-rbac.yaml k8s-admin.yaml
dashboard-secret.yaml k8s-cert
2. 创建相关组件
[root@master01 dashboard]# kubectl create -f dashboard-rbac.yaml ##权限管理
role.rbac.authorization.k8s.io/kubernetes-dashboard-minimal created
rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard-minimal created
[root@master01 dashboard]# kubectl create -f dashboard-secret.yaml ##凭证资源
secret/kubernetes-dashboard-certs created
secret/kubernetes-dashboard-key-holder created
[root@master01dashboard]# kubectl create -f dashboard-configmap.yaml ##配置文件
configmap/kubernetes-dashboard-settings created
[root@master01 dashboard]# kubectl create -f dashboard-controller.yaml ##控制资源
serviceaccount/kubernetes-dashboard created
deployment.apps/kubernetes-dashboard created
[root@master01dashboard]# kubectl create -f dashboard-service.yaml ##提供web服务
service/kubernetes-dashboard created
3. 完成后查看创建在指定的kube-system命令空间下
[root@master01 dashboard]# kubectl get pods -n kube-system #
NAME READY STATUS RESTARTS AGE
kubernetes-dashboard-65f974f565-l29kg 1/1 Running 0 3m51s
4. 查看如何访问
[root@master01 dashboard]# kubectl get pods,svc -n kube-system
NAME READY STATUS RESTARTS AGE
pod/kubernetes-dashboard-65f974f565-l29kg 1/1 Running 0 5m56s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes-dashboard NodePort 10.0.0.175 <none> 443:30001/TCP 5m48s
二 解决谷歌浏览器访问web界面问题
访问网址:https://20.0.0.102:30001,打开开发者工具,查看security发现缺少证书(火狐浏览器可以正常访问)
解决方法:
[root@master01 dashboard]# vim dashboard-cert.sh
cat > dashboard-csr.json <<EOF
"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]# cd ..
[root@master01 k8s]# vim dashboard-controller.yaml
args:
# PLATFORM-SPECIFIC ARGS HERE
- --auto-generate-certificates
- --tls-key-file=dashboard-key.pem ##添加以下两行(注意格式问题,不然会报错,要对齐,不能TAB,不要有多余的空格)
- --tls-cert-file=dashboard.pem
[root@master01 dashboard]# bash dashboard-cert.sh /root/k8s/k8s-cert/
2020/11/24 19:13:43 [INFO] generate received request
2020/11/24 19:13:43 [INFO] received CSR
2020/11/24 19:13:43 [INFO] generating key: rsa-2048
2020/11/24 19:13:43 [INFO] encoded CSR
2020/11/24 19:13:43 [INFO] signed certificate with serial number 475633400144465503923145971312459346798362792877
2020/11/24 19:13:43 [WARNING] This certificate lacks a "hosts" field. This makes it unsuitable for
websites. For more information see the Baseline Requirements for the Issuance and Management
of Publicly-Trusted Certificates, v.1.1.6, from the CA/Browser Forum (https://cabforum.org);
specifically, section 10.2.3 ("Information Requirements").
secret "kubernetes-dashboard-certs" deleted
secret/kubernetes-dashboard-certs created
[root@master01 dashboard]# kubectl apply -f dashboard-controller.yaml
serviceaccount/kubernetes-dashboard unchanged
Warning: kubectl apply should be used on resource created by either kubectl create --save-config or kubectl apply
deployment.apps/kubernetes-dashboard configured
此时浏览器访问,点击高级,点击继续前往20.0.0.102(不安全),会出现以下界面
##生成令牌
[root@master01 dashboard]# kubectl create -f k8s-admin.yaml
serviceaccount/dashboard-admin created
clusterrolebinding.rbac.authorization.k8s.io/dashboard-admin created
[root@master01 dashboard]# kubectl get secret -n kube-system
NAME TYPE DATA AGE
dashboard-admin-token-99hdr kubernetes.io/service-account-token 3 33s
default-token-kgmvl kubernetes.io/service-account-token 3 10h
kubernetes-dashboard-certs Opaque 11 3m58s
kubernetes-dashboard-key-holder Opaque 2 62m
kubernetes-dashboard-token-5vkh7 kubernetes.io/service-account-token 3 16m
[root@master01 dashboard]# kubectl describe secret dashboard-admin-token-99hdr -n kube-system
Name: dashboard-admin-token-99hdr
Namespace: kube-system
Labels: <none>
Annotations: kubernetes.io/service-account.name: dashboard-admin
kubernetes.io/service-account.uid: aec07453-2e4b-11eb-bed9-000c294ff7ea
Type: kubernetes.io/service-account-token
Data
====
ca.crt: 1359 bytes
namespace: 11 bytes
token: eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkYXNoYm9hcmQtYWRtaW4tdG9rZW4tOTloZHIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGFzaGJvYXJkLWFkbWluIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiYWVjMDc0NTMtMmU0Yi0xMWViLWJlZDktMDAwYzI5NGZmN2VhIiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOmRhc2hib2FyZC1hZG1pbiJ9.HNCIU1nhf80oGskJ7VwmeSZ9RRgu5_Fb9T6bmShEMcGxXu84HQMkB4bCw32Nj_li05aO5aiuFeQcDXEsGebL4LGkTzf9c1ZbkZyNaOUXdWYs0Z59f5UckZ9f93Gkl_2dIVWwIQ8BOF_t4cTAFttP9NA9Sc61KOC4qdSrCk2k1LEfVENpwoGowchzjuaNQ6mIqNst8DGfZnuTyDzJEtDhwe5fL_kCy63nTDtZBZYyT-Ro7vRCF2JFuiI8PMeSuTz755v2d26n6mgQHrf1Im7fIMRoDAtTjOcZzxsJaOp96Npvciwtzt4-j4Si0Xd1wq8Ptj8cA890E6HixQicdMvYsg
##复制token:后面的密钥到浏览器上
输入密钥,此时成功进入web界面
更多推荐
已为社区贡献2条内容
所有评论(0)