2020年3月6日 星期五

CentOS 7.6上安裝 Kubernetes(二)監控儀表板


遲來的Part2,經歷上集成功安裝完docker和Kubernetes套件後,總是使用指令與腳本來創建與管理容器實在很辛苦,感覺也有些不完整,接下來我們要開始安裝可圖示化的dashboard與監控mertrics套件,讓Kubernetes更易於管理。



dashboard Installation


到以下位置抓取dashboard容器範本,於範本中新增紅字部分,其中dashboard的nodePort可以自定義,本例為32222。
[root@server ~]# cd /tmp && wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta3/aio/deploy/recommended.yaml
[root@server tmp]# mv recommended.yaml kubernetes-dashboard_v2.0.0-beta3.yaml
[root@server tmp]# nano v2.0.0-beta3.yaml

kind: Service
apiVersion: v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace:kube-system
  namespace:kubernetes-dashboard

spec:
  type: NodePort
  ports:
    - port: 443
      targetPort: 8443
      nodePort: 32222
  selector:
    k8s-app: kubernetes-dashboard
創建一個給dashboard登入的管理者帳戶
[root@server tmp]# nano admin-sa.yaml

kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
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
  namespace: kubernetes-dashboard

---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin
  namespace: kube-system
  namespace: kubernetes-dashboard

  labels:
    kubernetes.io/cluster-service: "true"
    addonmanager.kubernetes.io/mode: Reconcile
匯入以上兩個範本
[root@server tmp]# kubectl apply -f kubernetes-dashboard_v2.0.0-beta3.yaml
[root@server tmp]# kubectl apply -f admin-sa.yaml
取得dashboard管理者登入密鑰,稍後登入dashboard會需要用到
[root@server tmp]# kubectl get secret `kubectl get secret -n kubernetes-dashboard | grep admin-token | awk '{print $1}'` -o jsonpath={.data.token} -n kubernetes-dashboard | base64 -d
透過server的外網或內網IP開啟Firefox瀏覽器強制登入沒有憑證的kubernetes dashboard入口。[進階]>[接受風險並繼續]

選取token並複製貼上管理者登入密鑰

圖示化後的Kubernetes變得一目了然,成為了熟悉的Google家族風格GUI管理頁面

驗證一下節點部分,可以看到原先三台叢集主機的基本資訊

點進命名空間的Pods,檢查看不到相關資源使用情況

此時需要再加裝mertrics-server套件,並對安裝範本稍作修改
[root@server tmp]# yum install git
[root@server tmp]# git clone https://github.com/kubernetes-incubator/metrics-server.git
[root@server tmp]# cd metrics-server/deploy/kubernetes
[root@server kubernetes]# metrics-server-deployment.yam

    spec:
      serviceAccountName: metrics-server
      volumes:
      # mount in tmp so we can safely use from-scratch images and/or read-only containers
      - name: tmp-dir
        emptyDir: {}
      containers:
      - name: metrics-server
        image: k8s.gcr.io/metrics-server-amd64:v0.3.3
        imagePullPolicy: IfNotPresent
        command:
            - /metrics-server
            - --kubelet-preferred-address-types=InternalIP
            - --kubelet-insecure-tls
        volumeMounts:
        - name: tmp-dir
          mountPath: /tmp 
匯入mertrics-server範本
[root@server kubernetes]# kubectl apply -f .
需要稍待片刻資源監控才會生效
[root@server kubernetes]# kubectl top nodes
error: metrics not available yet
片刻到了!
[root@server kubernetes]# kubectl top nodes
NAME     CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%   
master   143m         7%     836Mi           22%       
node01   55m          2%     420Mi           11%
回頭來看看dashboard,已經能顯示出更多的資源使用狀況



0 意見: