k8s dashboard_【大强哥-k8s从入门到放弃02】Kubernetes1.17部署Dashboard2.0
號外號外,后面所有提升視頻都會更新到知乎和B站上去,不會直接發(fā)群里了,哈哈,能看懂這句話的我都認識,大家可以先關(guān)注一下,我知乎上的所有文檔也會錄成視頻
更多視頻詳見 楊哥天云:https://space.bilibili.com/514805677
我馬上就開B站賬號,錄制點兒走心的視頻,呼呼
開始正題
注:因為本次部署在Centos8.1上,Dashboard必須使用2.0-rc6以上版本,rc6以下測試部署不成功
一、Dashboard介紹
Dashboard 是基于網(wǎng)頁的 Kubernetes 用戶界面。您可以使用 Dashboard 將容器應(yīng)用部署到 Kubernetes 集群中,也可以對容器應(yīng)用排錯,還能管理集群資源。您可以使用 Dashboard 獲取運行在集群中的應(yīng)用的概覽信息,也可以創(chuàng)建或者修改 Kubernetes 資源(如 Deployment,Job,DaemonSet 等等)。例如,您可以對 Deployment 實現(xiàn)彈性伸縮、發(fā)起滾動升級、重啟 Pod 或者使用向?qū)?chuàng)建新的應(yīng)用。
二、獲取并修改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應(yīng)用配置文件
# 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可能無法訪問這個頁面,這里使用火狐訪問
火狐瀏覽器訪問
創(chuàng)建一個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所做的操作大部分都可以可視化操作
比如
2. 執(zhí)行命令以及日志追蹤
3. 編輯資源的yaml文件
4. 導(dǎo)入yaml文件創(chuàng)建,更新資源等等
你都看到這里了,不點個贊么,不關(guān)注一下么,不轉(zhuǎn)發(fā)一下么
四、自己制作證書
1、刪除上面創(chuàng)建的各種資源
# kubectl delete -f create-admin.yaml # kubectl delete -f dashboard-admin-bind-cluster-role.yaml # kubectl delete -f recommended.yaml2、修改recommended.yaml文件
#因為我們要手動創(chuàng)建名稱空間,把這里的創(chuàng)建刪除掉,不然如果出了錯用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=36003、創(chuàng)建證書
# mkdir /root/certs # cd /root/certs/創(chuàng)建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 創(chuàng)建命名空間 # kubectl create namespace kubernetes-dashboard創(chuàng)建kubernetes-dashboard-certs對象 # kubectl create secret generic kubernetes-dashboard-certs --from-file=/root/certs/dashboard.key --from-file=/root/certs/dashboard.crt -n kubernetes-dashboard4、安裝 Dashboard
創(chuàng)建賬號綁定權(quán)限 # 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檢查結(jié)果 # kubectl get pods -A -o wide # kubectl get service -n kubernetes-dashboard -o wide5、查看用戶Token
# kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')6、訪問
五、安裝 metrics-server 插件
1、簡單介紹
Heapster已經(jīng)被Metrics-Server取代,如果使用Kubernetes的自動擴容功能的話,那首先得有一個插件,然后該插件將收集到的信息(cpu、memory..)與自動擴容的設(shè)置的值進行比對,自動調(diào)整pod數(shù)量。關(guān)于該插件,在kubernetes的早些版本中采用的是heapster,1.13版本正式發(fā)布后,丟棄了heapster,官方推薦采用metrics-sever。
2、下載相關(guān)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.yaml3、修改安裝腳本
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: # 添加以下內(nèi)容- --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: /tmp5、執(zhí)行安裝腳本并產(chǎn)看結(jié)果
#安裝 [root@k8s-master 1.8+]# kubectl create -f 。#1-2分鐘后查看結(jié)果 [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和內(nèi)存使用情況了
你都看完了,不點個贊么,不關(guān)注一下么,不轉(zhuǎn)發(fā)一下么
【大強哥-k8s從入門到放棄01】Kubernetes容器編排入門 - 云計算大強哥的文章 - 知乎 https://zhuanlan.zhihu.com/p/112963721
Centos8.1部署kubernetes1.17 - 云計算大強哥的文章 - 知乎 https://zhuanlan.zhihu.com/p/112834020
總結(jié)
以上是生活随笔為你收集整理的k8s dashboard_【大强哥-k8s从入门到放弃02】Kubernetes1.17部署Dashboard2.0的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 每天久坐超6小时增加12种疾病风险:躺着
- 下一篇: Linux绘图函数与驱动,Linux中与