号外号外,后面所有提升视频都会更新到知乎和B站上去,不会直接发群里了,哈哈,能看懂这句话的我都认识,大家可以先关注一下,我知乎上的所有文档也会录成视频
更多视频详见 杨哥天云:https://space.bilibili.com/514805677
我马上就开B站账号,录制点儿走心的视频,呼呼
开始正题
注:因为本次部署在Centos8.1上,Dashboard必须使用2.0-rc6以上版本,rc6以下测试部署不成功
一、Dashboard介绍
Dashboard 是基于网页的 Kubernetes 用户界面。您可以使用 Dashboard 将容器应用部署到 Kubernetes 集群中,也可以对容器应用排错,还能管理集群资源。您可以使用 Dashboard 获取运行在集群中的应用的概览信息,也可以创建或者修改 Kubernetes 资源(如 Deployment,Job,DaemonSet 等等)。例如,您可以对 Deployment 实现弹性伸缩、发起滚动升级、重启 Pod 或者使用向导创建新的应用。
二、获取并修改Yaml文件
GitHub上目前最新版本是dashboard v2.0.0-rc6
项目地址 https://github.com/kubernetes/dashboard/releases
# wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta8/aio/deploy/recommended.yaml
修改service通过NodePort方式访问K8S Dashboard
# vim recommended.yaml
应用配置文件
# kubectl apply -f recommended.yaml
查看pod和service
[root@master dashboard1]# kubectl get pod -o wide -n kubernetes-dashboard
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
dashboard-metrics-scraper-7b8b58dc8b-29wxq 1/1 Running 0 19m 10.244.2.18 node2 <none> <none>
kubernetes-dashboard-755dcb9575-fj8jl 1/1 Running 0 19m 10.244.1.28 node1 <none> <none>
[root@master dashboard1]# kubectl get svc -o wide -n kubernetes-dashboard
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
dashboard-metrics-scraper ClusterIP 10.98.53.94 <none> 8000/TCP 19m k8s-app=dashboard-metrics-scraper
kubernetes-dashboard NodePort 10.109.85.22 <none> 443:30001/TCP 19m k8s-app=kubernetes-dashboard
访问Dashboard
注:通过Chrome、IE、Safari可能无法访问这个页面,这里使用火狐访问
火狐浏览器访问
创建一个dashboard用户
# vim create-admin.yaml
获取Token
[root@master dashboard1]# kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')
Name: admin-user-token-z4jp6
Namespace: kubernetes-dashboard
Labels: <none>
Annotations: kubernetes.io/service-account.name: admin-userkubernetes.io/service-account.uid: 349285ce-741d-4dc1-a600-1843a6ec9751Type: kubernetes.io/service-account-tokenData
====
token: eyJhbGciOiJSUzI1NiIsImtpZCI6InY5M1pSc3RpejBVZ0x6LTNSbWlCc2t5b01ualNZWnpYMVB5YzUwNmZ3ZmsifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi11c2VyLXRva2VuLXo0anA2Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImFkbWluLXVzZXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiIzNDkyODVjZS03NDFkLTRkYzEtYTYwMC0xODQzYTZlYzk3NTEiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZXJuZXRlcy1kYXNoYm9hcmQ6YWRtaW4tdXNlciJ9.JtCa0VC7tYtIGLWlwSKUwqSL0T8eRvZ8jk_AUxB4Atmi5PjF9IjAHNNwGS3HaTL3Q86fCI8MvYGf3Eplk9X-n-g9WsrFIxXxa0wGJxZp0d8R78A6vuN7I7Zd5CeQm_O2ycTUuQhYnSZlNplF8X033QOfjOoFnKKevbn2094XXWWZuAsT9haGnZ8BX92DmYzsaMyLesfv7ZziJD80KgSQ8_jtb0n55zw5cedYTsRCZgofJ_o9U5SUW3I0AXG-vVhI28m0sMBjZkuMppfB4eMLnSDH-XAw3Gvwe_2NOLfS4hBTkYu7gJket-gif9Cs8Ybkzvf2qXdZW5fydZUuSylafg
ca.crt: 1025 bytes
namespace: 20 bytes
登录dashboard
登陆后界面
三、使用Dashboard
在Dashboard中,我们之前通过kubectl所做的操作大部分都可以可视化操作
比如
- 可以对Deployment做伸缩
2. 执行命令以及日志追踪
3. 编辑资源的yaml文件
4. 导入yaml文件创建,更新资源等等
你都看到这里了,不点个赞么,不关注一下么,不转发一下么
四、自己制作证书
1、删除上面创建的各种资源
# kubectl delete -f create-admin.yaml
# kubectl delete -f dashboard-admin-bind-cluster-role.yaml
# kubectl delete -f recommended.yaml
2、修改recommended.yaml文件
#因为我们要手动创建名称空间,把这里的创建删除掉,不然如果出了错用yaml删除ns的时候也会把里面的资源全部删掉
#apiVersion: v1
#kind: Namespace
#metadata:
# name: kubernetes-dashboard---
#增加直接访问端口
kind: Service
apiVersion: v1
metadata:labels:k8s-app: kubernetes-dashboardname: kubernetes-dashboardnamespace: kubernetes-dashboard
spec:type: NodePort #增加ports:- port: 443targetPort: 8443nodePort: 30008 #增加selector:k8s-app: kubernetes-dashboard---
#注释掉kubernetes-dashboard-certs对象声明
#apiVersion: v1
#kind: Secret
#metadata:
# labels:
# k8s-app: kubernetes-dashboard
# name: kubernetes-dashboard-certs
# namespace: kubernetes-dashboard
#type: Opaque---template:metadata:labels:k8s-app: kubernetes-dashboardspec:containers:- name: kubernetes-dashboardimage: kubernetesui/dashboard:v2.0.0-rc6imagePullPolicy: IfNotPresentports:- containerPort: 8443protocol: TCPargs:#- --auto-generate-certificates ##注释掉自动生成证书- --namespace=kubernetes-dashboard# Uncomment the following line to manually specify Kubernetes API server Host# If not specified, Dashboard will attempt to auto discover the API server and connect# to it. Uncomment only if the default does not work.# - --apiserver-host=http://my-address:port# 添加我们自己生成的证书名称- --tls-cert-file=/dashboard.crt- --tls-key-file=/dashboard.key- --token-ttl=3600
3、创建证书
# mkdir /root/certs
# cd /root/certs/创建key文件
# openssl genrsa -out dashboard.key 2048证书请求
# openssl req -new -out dashboard.csr -key dashboard.key -subj '/CN=192.168.1.201'自签证书
# openssl x509 -req -days 365 -in dashboard.csr -signkey dashboard.key -out dashboard.crt 创建命名空间
# kubectl create namespace kubernetes-dashboard创建kubernetes-dashboard-certs对象
# kubectl create secret generic kubernetes-dashboard-certs --from-file=/root/certs/dashboard.key --from-file=/root/certs/dashboard.crt -n kubernetes-dashboard
4、安装 Dashboard
创建账号绑定权限
# vim create-admin.yaml
apiVersion: v1
kind: ServiceAccount
metadata:name: admin-usernamespace: kubernetes-dashboard---apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:name: admin-user
roleRef:apiGroup: rbac.authorization.k8s.iokind: ClusterRolename: cluster-admin
subjects:
- kind: ServiceAccountname: admin-usernamespace: kubernetes-dashboard安装Dashboard
# kubectl create -f ~/recommended.yaml检查结果
# kubectl get pods -A -o wide
# kubectl get service -n kubernetes-dashboard -o wide
5、查看用户Token
# kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')
6、访问
五、安装 metrics-server 插件
1、简单介绍
Heapster已经被Metrics-Server取代,如果使用Kubernetes的自动扩容功能的话,那首先得有一个插件,然后该插件将收集到的信息(cpu、memory..)与自动扩容的设置的值进行比对,自动调整pod数量。关于该插件,在kubernetes的早些版本中采用的是heapster,1.13版本正式发布后,丢弃了heapster,官方推荐采用metrics-sever。
2、下载相关yaml文件
https://github.com/kubernetes-incubator/metrics-server
[root@k8s-master ~]# git clone https://github.com/kubernetes-incubator/metrics-server.git
[root@k8s-master ~]# cd metrics-server/deploy/1.8+/
[root@k8s-master 1.8+]# ll
总用量 28
-rw-r--r-- 1 root root 384 4月 28 09:46 aggregated-metrics-reader.yaml
-rw-r--r-- 1 root root 308 4月 28 09:46 auth-delegator.yaml
-rw-r--r-- 1 root root 329 4月 28 09:46 auth-reader.yaml
-rw-r--r-- 1 root root 298 4月 28 09:46 metrics-apiservice.yaml
-rw-r--r-- 1 root root 815 4月 28 09:46 metrics-server-deployment.yaml
-rw-r--r-- 1 root root 291 4月 28 09:46 metrics-server-service.yaml
-rw-r--r-- 1 root root 502 4月 28 09:46 resource-reader.yaml
3、修改安装脚本
vim metrics-server-deployment.yaml
---
apiVersion: v1
kind: ServiceAccount
metadata:name: metrics-servernamespace: kube-system
---
apiVersion: apps/v1
kind: Deployment
metadata:name: metrics-servernamespace: kube-systemlabels:k8s-app: metrics-server
spec:selector:matchLabels:k8s-app: metrics-servertemplate:metadata:name: metrics-serverlabels:k8s-app: metrics-serverspec:serviceAccountName: metrics-servervolumes:# mount in tmp so we can safely use from-scratch images and/or read-only containers- name: tmp-diremptyDir: {}containers:- name: metrics-serverimage: mirrorgooglecontainers/metrics-server-amd64:v0.3.6 # 修改镜像下载地址args: # 添加以下内容- --cert-dir=/tmp- --secure-port=4443- --kubelet-insecure-tls- --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostnameports:- name: main-portcontainerPort: 4443protocol: TCPsecurityContext:readOnlyRootFilesystem: truerunAsNonRoot: truerunAsUser: 1000imagePullPolicy: AlwaysvolumeMounts:- name: tmp-dirmountPath: /tmp
5、执行安装脚本并产看结果
#安装
[root@k8s-master 1.8+]# kubectl create -f 。#1-2分钟后查看结果
[root@k8s-master 1.8+]# kubectl top nodes
NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%
k8s-master 256m 12% 2002Mi 52%
k8s-node1 103m 5% 1334Mi 34%
k8s-node2 144m 7% 1321Mi 34%
再回到dashboard界面可以看到CPU和内存使用情况了
你都看完了,不点个赞么,不关注一下么,不转发一下么
【大强哥-k8s从入门到放弃01】Kubernetes容器编排入门 - 云计算大强哥的文章 - 知乎 https://zhuanlan.zhihu.com/p/112963721
Centos8.1部署kubernetes1.17 - 云计算大强哥的文章 - 知乎 https://zhuanlan.zhihu.com/p/112834020