K8S 部署 Web UI
在早期的版本中 Kubernetes可以在 Dashboard 中看到 heapster 提供的一些图表信息,
在后续的版本中会陆续移除掉 heapster,现在更加流行的监控工具是 prometheus,prometheus 是 Google 内部监控报警系统的开源版本,所以这里的Dashboard 不会看到有图表信息。
1.下载官方的yaml文件
$ wget https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml
如果网络不好,不能直接下载,需要手动创建kubernetes-dashboard.yaml文件
2.修改yaml文件
修改两个地方,
第一个是修改镜像,
第二个是添加一个type,指定端口类型为 NodePort,这样外界可以通过地址 nodeIP:nodePort 访问 dashboard;
完整的yaml配置文件如下:
kubernetes-dashboard.yaml
apiVersion: v1 kind: ServiceAccount metadata: name: kubernetes-dashboard namespace: kube-system --- apiVersion: rbac.authorization.k8s.io/v1beta1 kind: ClusterRoleBinding metadata: name: kubernetes-dashboard labels: k8s-app: kubernetes-dashboard roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects: - kind: ServiceAccount name: kubernetes-dashboard namespace: kube-system --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: kubernetes-dashboard namespace: kube-system labels: k8s-app: kubernetes-dashboard kubernetes.io/cluster-service: "true" addonmanager.kubernetes.io/mode: Reconcile spec: selector: matchLabels: k8s-app: kubernetes-dashboard template: metadata: labels: k8s-app: kubernetes-dashboard annotations: scheduler.alpha.kubernetes.io/critical-pod: '' spec: serviceAccountName: kubernetes-dashboard containers: - name: kubernetes-dashboard image: docker.io/mritd/kubernetes-dashboard-amd64 resources: limits: cpu: 100m memory: 300Mi requests: cpu: 100m memory: 100Mi ports: - containerPort: 9090 livenessProbe: httpGet: path: / port: 9090 initialDelaySeconds: 30 timeoutSeconds: 30 tolerations: - key: "CriticalAddonsOnly" operator: "Exists" --- apiVersion: v1 kind: Service metadata: name: kubernetes-dashboard namespace: kube-system labels: k8s-app: kubernetes-dashboard kubernetes.io/cluster-service: "true" addonmanager.kubernetes.io/mode: Reconcile spec: selector: k8s-app: kubernetes-dashboard type: NodePort ports: - port: 9090 targetPort: 9090 nodePort: 32000
3.执行安装
$ kubectl create -f kubernetes-dashboard.yaml
查看pod运行状态
$ kubectl get pods,svc -n kube-system
NAME READY STATUS RESTARTS AGE pod/coredns-8686dcc4fd-j9vgq 1/1 Running 31 4d8h pod/coredns-8686dcc4fd-vzsgs 1/1 Running 31 4d8h pod/etcd-k8s-master 1/1 Running 7 4d8h pod/kube-apiserver-k8s-master 1/1 Running 6 4d8h pod/kube-controller-manager-k8s-master 1/1 Running 7 4d8h pod/kube-flannel-ds-amd64-4mx58 1/1 Running 7 4d8h pod/kube-flannel-ds-amd64-887vr 1/1 Running 2 4d8h pod/kube-flannel-ds-amd64-rm9nz 1/1 Running 5 4d8h pod/kube-proxy-hdv89 1/1 Running 7 4d8h pod/kube-proxy-l2scz 1/1 Running 6 4d8h pod/kube-proxy-rqh8n 1/1 Running 3 4d8h pod/kube-scheduler-k8s-master 1/1 Running 6 4d8h pod/kubernetes-dashboard-795b8c5854-4dnf4 1/1 Running 2 3d5h NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/kubernetes-dashboard NodePort 10.1.165.28 <none> 9090:32000/TCP 3d5h
注意:这里查看到service端口为32000,因此我们访问时需要使用32000端口访问
4.进入ui界面