Kubernetes(k8s)是Google开源的一个容器编排引擎,它支持自动化部署、大规模可伸缩、应用容器化管理,具备可移植、可扩展、自动化等特点。
通过 Kubernetes Dashboard 不仅可以很直观地查看各种资源信息、日志信息、系统资源使用等,还可以创建容器应用、管理资源、更新资源文件等等。
0x01 部署Dashboard
Kubernetes默认会把Pods分布到Worker节点,但我还是喜欢把Dashboard部署在Master节点上:
kubectl label nodes k8sm01 k8sm02 k8sm03 master=master
获取默认配置文件:
wget -o dashboard2.yaml https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta6/aio/deploy/recommended.yaml
外部网络访问无法访问使用默认配置创建的控制面板,因此需要对配置文件进行一些调整:
... kind: Service apiVersion: v1 metadata: labels: k8s-app: kubernetes-dashboard name: kubernetes-dashboard namespace: kubernetes-dashboard spec: ### 新增 ### type: NodePort ports: - port: 443 targetPort: 8443 ### 新增 ### nodePort: 30080 selector: k8s-app: kubernetes-dashboard ... kind: ConfigMap labels: k8s-app: kubernetes-dashboard name: kubernetes-dashboard namespace: kubernetes-dashboard 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 ### 注释 ### #imagePullPolicy: Always ... kind: Deployment apiVersion: apps/v1 metadata: labels: k8s-app: kubernetes-dashboard name: kubernetes-dashboard namespace: kubernetes-dashboard ... nodeSelector: ### 修改 ### "master": master # Comment the following tolerations if Dashboard must not be deployed on master ... kind: Deployment apiVersion: apps/v1 metadata: labels: k8s-app: dashboard-metrics-scraper name: dashboard-metrics-scraper namespace: kubernetes-dashboard ... serviceAccountName: kubernetes-dashboard nodeSelector: "kubernetes.io/os": linux # Comment the following tolerations if Dashboard must not be deployed on master ... ### 追加 ### --- ### Dashbboard账户 ### apiVersion: v1 kind: ServiceAccount metadata: labels: k8s-app: kubernetes-dashboard name: dashboard-admin namespace: kubernetes-dashboard --- ### Dashbboard权限 ### apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: dashboard-admin-bind-cluster-role labels: k8s-app: kubernetes-dashboard roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects: - kind: ServiceAccount name: dashboard-admin namespace: kubernetes-dashboard
本人有已修改好的配置文件,可从本站分享点下载,现在创建dashboard容器:
kubectl apply -f dashboard2.yaml
通过以下命令获取登录dashboard的token:
kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep dashboard-admin | awk '{print $1}')
最后访问Dashboard,比如https://10.10.200.200:30080,使用刚获取到的token即可登录。
0x02 集成Heapster
通过Heapster插件图形化展现集群度量指标信息。
cd /opt/kubernetes/ git clone https://github.com/kubernetes/heapster.git ll deploy/kube-config/influxdb/
以上目录中的yaml文件分别对应heapster、influxdb和grafana,通过以下脚本拉取相应的镜像:
#!/bin/bash images=(heapster-amd64:v1.5.4 heapster-influxdb-amd64:v1.5.2 heapster-grafana-amd64:v5.0.4) for image in ${images[@]} do docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/${image} docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/${image} k8s.gcr.io/${image} done
参照Kubernetes使用教程·配置文件修改yaml文件(本文略),然后启动服务:
kubectl create -f deploy/kube-config/influxdb/ # 删除服务 # kubectl delete -f deploy/kube-config/influxdb/ kubectl get pods -n kube-system
如果顺利,视数据量等待n分钟,就可以通过dashboard看到图形化的集群度量指标信息。如果一直没有图形化,请检查heapster.yaml配置是否正确。
原创文章禁止转载:技术学堂 » Kubernetes集群部署教程四·Dashboard控制面板