k8s学习笔记(1)-安装dashboard
source link: http://vearne.cc/archives/39395
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
版权声明 本站原创文章 由 萌叔 发表
转载请注明 萌叔 | http://vearne.cc
警告:本文仅用于萌叔自己总结之用,对其它人而言可能毫无营养,没有阅读价值。
Dashboard 是基于网页的 Kubernetes 用户界面。 你可以使用 Dashboard 将容器应用部署到 Kubernetes 集群中,也可以对容器应用排错,还能管理集群资源。 你可以使用 Dashboard 获取运行在集群中的应用的概览信息,也可以创建或者修改 Kubernetes 资源 (如 Deployment,Job,DaemonSet 等等)。
通过一段时间的使用感受而言,Dashboard虽然做的差强人意,但聊胜于无。2. 安装&配置
wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.4/aio/deploy/recommended.yaml
建议脚本下载以后,先大致阅读以下
2.1 修改yaml
kind: Service
apiVersion: v1
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kubernetes-dashboard
spec:
ports:
- port: 443
targetPort: 8443
type: NodePort # 改为NodePort方式暴露service
selector:
k8s-app: kubernetes-dashboard
2.2 安装
kubectl apply -f recommended.yaml
安装完成以后
╰─$ kubectl get svc -n kubernetes-dashboard
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
dashboard-metrics-scraper ClusterIP 10.68.53.228 <none> 8000/TCP 18h
kubernetes-dashboard NodePort 10.68.254.87 <none> 443:37736/TCP 17h
3. 访问web UI
3.1 方式1 通过 kubectl proxy
默认K8S采用Flannel网络的模型的情况下,集群内部和外部网络是不能直接互联的,但是能够通过kubectl proxy作为代理,进行通讯
kubectl proxy
在浏览器上访问,以下地址
http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
3.2 方式2 通过NodePort端口
刚才我们修改了Service/kubernetes-dashboard,将它以NodePort的方式暴露在外部网络。可以直接在浏览器中访问
https://{masterIP}:37736/
4. 通讯与鉴权
Dashboard自动生成了一个自签名的证书,用于HTTPS通讯,
因此浏览器会有不安全警告(可以将证书导出,并添加到操作系统的信任列表里,消除此问题)
apiVersion: v1
kind: Secret
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard-certs
namespace: kubernetes-dashboard
type: Opaque
最后要能够login,还需要使用token登录
4.1 生成kubernetes集群最高权限admin用户的token
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: admin
annotations:
rbac.authorization.kubernetes.io/autoupdate: "true"
roleRef:
kind: ClusterRole
name: cluster-admin
apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
name: admin
namespace: kube-system
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin
namespace: kube-system
labels:
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile
kubectl create -f admin-role.yaml
创建完成后获取secret中token的值。
# 获取admin-token的secret名字
$ kubectl -n kube-system get secret|grep admin-token
admin-token-nwphb kubernetes.io/service-account-token 3 6m
# 获取token的值
$ kubectl -n kube-system describe secret admin-token-nwphb
Name: admin-token-nwphb
Namespace: kube-system
Labels: <none>
Annotations: kubernetes.io/service-account.name=admin
kubernetes.io/service-account.uid=f37bd044-bfb3-11e7-87c0-f4e9d49f8ed0
Type: kubernetes.io/service-account-token
Data
====
namespace: 11 bytes
token: 非常长的字符串
ca.crt: 1310 bytes
2020年10月20日 如果你使用的是easzlab/kubeasz ansible安装脚本的话,当你执行完
ansible-playbook 07.cluster-addon.yml
你会发现kubernetes-dashboard已经安装完毕,且以NodePort方式暴露出来了。
╰─$ kubectl get svc -n kube-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
dashboard-metrics-scraper ClusterIP xx.xx.xx.xx <none> 8000/TCP 123m
kubernetes-dashboard NodePort xx.xx.xx.xx <none> 443:25230/TCP 123m
metrics-server ClusterIP xx.xx.xx.xx <none> 443/TCP 123m
kube-dns ClusterIP xx.xx.xx.xx <none> 53/UDP,53/TCP,9153/TCP 123m
2020年12月15日 如果Kubernetes Dashboard由于自身证书问题导致一些浏览器不能打开的问题,请看参考资料4
请我喝杯咖啡
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK