通过Kubernetes Dashboard创建服务

本地访问 Kubernetes Dashboard (Web UI)

前提条件

在本地使用 Kubernetes Dashboard 前,用户需要先配置好kubectl,能通过kubectl连接百度智能云的 Kubernetes 集群。

操作步骤

创建Dashboard服务。在本地通过kubectl工具,可以在kubernetes集群里创建一个Dashboard应用。

$ kubectl create -f dashboard.yaml
deployment "kubernetes-dashboard" created
service "kubernetes-dashboard" created

对应的dashboard.yaml文件为:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kube-system
spec:
  replicas: 1
  selector:
    matchLabels:
      app: kubernetes-dashboard
  template:
    metadata:
      labels:
        app: kubernetes-dashboard
    spec:
      containers:
      - name: kubernetes-dashboard
        image: hub.baidubce.com/public/dashboard:v1.5.0-caas
        imagePullPolicy: Always
        ports:
        - containerPort: 9090
          protocol: TCP
        volumeMounts:
        - name: "kubeconfig"
          mountPath: "/etc/kubernetes/"
          readOnly: true
        args:
          - --kubeconfig=/etc/kubernetes/config
        livenessProbe:
          httpGet:
            path: /
            port: 9090
          initialDelaySeconds: 30
          timeoutSeconds: 30
      volumes:
      - name: "kubeconfig"
        hostPath:
          path: "/root/.kube/"
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kube-system
spec:
  replicas: 1
  selector:
    matchLabels:
      app: kubernetes-dashboard
  template:
    metadata:
      labels:
        app: kubernetes-dashboard
    spec:
      containers:
      - name: kubernetes-dashboard
        image: hub.baidubce.com/public/dashboard:v1.5.0-caas
        imagePullPolicy: Always
        ports:
        - containerPort: 9090
          protocol: TCP
        volumeMounts:
        - name: "kubeconfig"
          mountPath: "/etc/kubernetes/"
          readOnly: true
        args:
          - --kubeconfig=/etc/kubernetes/config
        livenessProbe:
          httpGet:
            path: /
            port: 9090
          initialDelaySeconds: 30
          timeoutSeconds: 30
      volumes:
      - name: "kubeconfig"
        hostPath:
          path: "/root/.kube/"
---
kind: Service
apiVersion: v1
metadata:
  labels:
    app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kube-system
spec:
  type: NodePort
  ports:
  - port: 80
    targetPort: 9090
  selector:
    app: kubernetes-dashboard

在创建好dashboard之后,使用kubectl proxy命令开启一个代理,连接到Kubernetes API Server。

kubectl proxy

成功开启代理后,可以在本地浏览器中访问http://localhost:8001/ui,连接到Dashboard。

服务创建

  1. 完成本地访问 Kubernetes Dashboard (Web UI)后,进入Dshboard页面,点击CREATE开始创建服务;

  2. 进入创建服务页面,在App name窗口中输入要创建的服务名称,在Container image 中输入服务的镜像,在Number of pods 中输入此服务需要使用的容器的数量(数量大于等于1);

  3. Service中选择External 完成EIP和BLB的配置,然后会暴漏出端口页面分别填写80 80,然后点击DEPLOY按钮开始服务创建;


  4. 等待服务创建成功,且页面需要手动刷新;

  5. 在创建成功页面点击Services按钮,进入services页面;

  6. 在此页面中会显示服务的外网地址;

  7. 在浏览器中输入外网地址,显示服务创建成功;

  8. 完成服务创建之后,用户可以登陆百度智能云平台,选择“产品服务>负载均衡 BLB”,进入BLB控制台查看负载均衡BLB的详细信息,具体操作步骤可以参考负载均衡操作指南