Kubernets搭建Kubernetes-dashboard

时间:2022-10-07 15:38:26

接上篇文章,在已经部署好Kubernetes的基础上部署kubernetes-dashboard,它是官方提供的用户管理Kubernets集群可视化工具;部署dashboard其实和在kubernets部署其他的应用一样,创建dashboard所需的Replication Controller、Service服务即可;

  注意Kubernets的Overlay Network要正常工作,每个节点都已经启动Flannel,并且docker启动时配置了Flannel提供的子网,或使用其他方式保证Container之间的连通,否则dashboard将无法正常工作;

Namespace##

  使用默认的Namespace也是可以得,因为dashboard算是属于系统应用所以这里使用Namespace把dashboard与其他App进行隔离,建议线上正式的Kubernetes环境都要使用Namespace;

  创建kube-namespace.yaml文件,内容如下:

apiVersion: v1
kind: Namespace
metadata:
name: kube-system

Replication Controller##

  Replication Controller用于保证pod期望状态与当前状态一致,还可对pod数量弹性伸缩,这里主要是保证dashboard的正常运行;

  创建kube-dashboard-rc.yaml文件:内容如下:

apiVersion: v1
kind: ReplicationController
metadata:
# Keep the name in sync with image version and
# gce/coreos/kube-manifests/addons/dashboard counterparts
name: kubernetes-dashboard-latest
namespace: kube-system
labels:
k8s-app: kubernetes-dashboard
version: latest
kubernetes.io/cluster-service: "true"
spec:
replicas: 1
selector:
k8s-app: kubernetes-dashboard
template:
metadata:
labels:
k8s-app: kubernetes-dashboard
version: latest
kubernetes.io/cluster-service: "true"
spec:
containers:
- name: kubernetes-dashboard
image: 192.168.2.144:5000/kkubernetes-dashboard-amd64
resources:
# keep request = limit to keep this container in guaranteed class
limits:
cpu: 100m
memory: 50Mi
requests:
cpu: 100m
memory: 50Mi
ports:
- containerPort: 9090
args:
- --apiserver-host=http://192.168.2.143:8080
livenessProbe:
httpGet:
path: /
port: 9090
initialDelaySeconds: 30
timeoutSeconds: 30

  由于kubernetes-dashboard-amd64如要被墙,这里下了index.alauda.cn/googlecontainer/kubernetes-dashboard-amd64放在本地私有仓库,使用了本地私有长裤镜像库kubernetes-dashboard-amd64;还要注意别忘了配置apiserver-host否则dashboard将无法连接到kubernets集群;

Service##

  service用于配置dashboard的label selector;

  创建kube-dashboard-svc.yaml文件,内容如下:

apiVersion: v1
kind: Service
metadata:
name: kubernetes-dashboard
namespace: kube-system
labels:
k8s-app: kubernetes-dashboard
kubernetes.io/cluster-service: "true"
spec:
selector:
k8s-app: kubernetes-dashboard
ports:
- port: 80
targetPort: 9090

kubernates中创建dashboard应用##

  1、创建namespace

kubectl -s 192.168.2.143:8080 create -f namespace.yaml

  2、创建replication Controller

kubectl -s 192.168.2.143:8080 create -f kube-dashboard-rc.yaml

  3、创建service

kubectl -s 192.168.2.143:8080 create -f kube-dashboard-svc.yaml

  查看dashboard启动情况

Kubernets搭建Kubernetes-dashboard

  Kubernetes dashboard访问地址:http://192.168.2.143:8080/ui 注意这里的地址是master节点的地址;

Kubernets搭建Kubernetes-dashboard

参考资料:

http://kubernetes.io/docs/user-guide/

文章首发地址:Solinx

http://www.solinx.co/archives/632