kubernetes部署2.0版本UI頁面,以及容器資源使用監控(2)

你們可能都知道k8s默認有個ui界面,可是呢,通常都使用的是1版本的,今天給你們部署的是2版本頁面node

完整部署文件 Github 地址:https://github.com/my-dlq/blog-example/tree/master/kubernetes/kubernetes-dashboard2.0.0-deploylinux

接下來開始部署git

部署一共分5個步驟:
一、建立RBAC
二、建立configmap和secret
三、建立dashboard
四、建立metrics-scraper
五、建立訪問的serviceaccountgithub

我吧文件直接都配好了放到了百度網盤,大家能夠直接下載解壓使用web

連接:https://pan.baidu.com/s/1wdp-zJE6FqpuJdGYgyESmg
提取碼:stzw api

完成以後就能夠經過web頁面訪問了app

這裏使用的是kubeadmin部署的,若是是二進制,須要修改api-server的參數否則沒法支持metrics-server服務的ide

一、建立 Dashboard RBAC 部署文件
cat > k8s-dashboard-rbac.yaml <<EOF
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kube-system

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kube-system
rules:ui

  • apiGroups: [""]
    resources: ["secrets"]
    resourceNames: ["kubernetes-dashboard-key-holder", "kubernetes-dashboard-certs", "kubernetes-dashboard-csrf"]
    verbs: ["get", "update", "delete"]
  • apiGroups: [""]
    resources: ["configmaps"]
    resourceNames: ["kubernetes-dashboard-settings"]
    verbs: ["get", "update"]
  • apiGroups: [""]
    resources: ["services"]
    resourceNames: ["heapster", "dashboard-metrics-scraper"]
    verbs: ["proxy"]
  • apiGroups: [""]
    resources: ["services/proxy"]
    resourceNames: ["heapster", "http:heapster:", "https:heapster:", "dashboard-metrics-scraper", "http:dashboard-metrics-scraper"]
    verbs: ["get"]

    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRole
    metadata:
    labels:
    k8s-app: kubernetes-dashboard
    name: kubernetes-dashboard
    rules:spa

  • apiGroups: ["metrics.k8s.io"]
    resources: ["pods", "nodes"]
    verbs: ["get", "list", "watch"]

    apiVersion: rbac.authorization.k8s.io/v1
    kind: RoleBinding
    metadata:
    labels:
    k8s-app: kubernetes-dashboard
    name: kubernetes-dashboard
    namespace: kube-system
    roleRef:
    apiGroup: rbac.authorization.k8s.io
    kind: Role
    name: kubernetes-dashboard
    subjects:

  • kind: ServiceAccount
    name: kubernetes-dashboard
    namespace: kube-system

    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRoleBinding
    metadata:
    name: kubernetes-dashboard
    namespace: kube-system
    roleRef:
    apiGroup: rbac.authorization.k8s.io
    kind: ClusterRole
    name: kubernetes-dashboard
    subjects:

  • kind: ServiceAccount
    name: kubernetes-dashboard
    namespace: kube-system
    EOF

部署
kubectl apply -f k8s-dashboard-rbac.yaml

二、建立 ConfigMap、Secret
cat >k8s-dashboard-configmap-secret.yaml<<EOF
apiVersion: v1
kind: Secret
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard-certs
namespace: kube-system
type: Opaque

apiVersion: v1
kind: Secret
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard-csrf
namespace: kube-system
type: Opaque
data:
csrf: ""

apiVersion: v1
kind: Secret
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard-key-holder
namespace: kube-system
type: Opaque

kind: ConfigMap
apiVersion: v1
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard-settings
namespace: kube-system
EOF

三、部署 Dashboard Config & Secret
kubectl apply -f k8s-dashboard-configmap-secret.yaml

建立 Dashboard Deploy 部署文件
cat >k8s-dashboard-deploy.yaml<<EOF
kind: Service
apiVersion: v1
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kube-system
spec:
type: NodePort
ports:

  • port: 443
    targetPort: 8443
    nodePort: 31001
    selector:
    k8s-app: kubernetes-dashboard

    kind: Deployment
    apiVersion: apps/v1
    metadata:
    labels:
    k8s-app: kubernetes-dashboard
    name: kubernetes-dashboard
    namespace: kube-system
    spec:
    replicas: 1
    revisionHistoryLimit: 10
    selector:
    matchLabels:
    k8s-app: kubernetes-dashboard
    template:
    metadata:
    labels:
    k8s-app: kubernetes-dashboard
    spec:
    containers:

    • name: kubernetes-dashboard
      image: kubernetesui/dashboard:v2.0.0-rc3
      ports:
      • containerPort: 8443
        protocol: TCP
        args:
      • --auto-generate-certificates
      • --namespace=kube-system #設置爲當前namespace
        volumeMounts:
      • name: kubernetes-dashboard-certs
        mountPath: /certs
      • mountPath: /tmp
        name: tmp-volume
        livenessProbe:
        httpGet:
        scheme: HTTPS
        path: /
        port: 8443
        initialDelaySeconds: 30
        timeoutSeconds: 30
        volumes:
    • name: kubernetes-dashboard-certs
      secret:
      secretName: kubernetes-dashboard-certs
    • name: tmp-volume
      emptyDir: {}
      serviceAccountName: kubernetes-dashboard
      tolerations:
    • key: node-role.kubernetes.io/master
      effect: NoSchedule
      EOF

部署 Dashboard Deploy
kubectl apply -f k8s-dashboard-deploy.yaml

四、建立 Dashboard Metrics 部署文件

cat >k8s-dashboard-metrics.yaml<<EOF
kind: Service
apiVersion: v1
metadata:
labels:
k8s-app: dashboard-metrics-scraper
name: dashboard-metrics-scraper
namespace: kube-system
spec:
ports:

  • port: 8000
    targetPort: 8000
    selector:
    k8s-app: dashboard-metrics-scraper

    kind: Deployment
    apiVersion: apps/v1
    metadata:
    labels:
    k8s-app: dashboard-metrics-scraper
    name: dashboard-metrics-scraper
    namespace: kube-system
    spec:
    replicas: 1
    revisionHistoryLimit: 10
    selector:
    matchLabels:
    k8s-app: dashboard-metrics-scraper
    template:
    metadata:
    labels:
    k8s-app: dashboard-metrics-scraper
    annotations:
    seccomp.security.alpha.kubernetes.io/pod: 'runtime/default'
    spec:
    containers:

    • name: dashboard-metrics-scraper
      image: kubernetesui/metrics-scraper:v1.0.3
      ports:
      • containerPort: 8000
        protocol: TCP
        livenessProbe:
        httpGet:
        scheme: HTTP
        path: /
        port: 8000
        initialDelaySeconds: 30
        timeoutSeconds: 30
        volumeMounts:
        • mountPath: /tmp
          name: tmp-volume
          securityContext:
          allowPrivilegeEscalation: false
          readOnlyRootFilesystem: true
          runAsUser: 1001
          runAsGroup: 2001
          serviceAccountName: kubernetes-dashboard
          nodeSelector:
          "beta.kubernetes.io/os": linux
          tolerations:
    • key: node-role.kubernetes.io/master
      effect: NoSchedule
      volumes:
    • name: tmp-volume
      emptyDir: {}

EOF
部署 Dashboard Metrics
kubectl apply -f k8s-dashboard-metrics.yaml

五、建立 Dashboard ServiceAccount 部署文件

cat > k8s-dashboard-token.yaml<<EOF
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

    apiVersion: v1
    kind: ServiceAccount
    metadata:
    name: admin
    namespace: kube-system
    labels:
    kubernetes.io/cluster-service: "true"
    addonmanager.kubernetes.io/mode: Reconcile
    EOF

部署訪問的 ServiceAccount

kubectl apply -f k8s-dashboard-token.yaml
獲取 Token
kubectl describe secret/$(kubectl get secret -n kube-system |grep admin|awk '{print $1}') -n kube-system

kubernetes部署2.0版本UI頁面,以及容器資源使用監控(2)

完成以後登錄頁面而後看看
kubernetes部署2.0版本UI頁面,以及容器資源使用監控(2)

看到了數據
kubernetes部署2.0版本UI頁面,以及容器資源使用監控(2)

好了2版本的web-ui就完成了有什麼問題能夠私信我哈

相關文章
相關標籤/搜索