dashboard本身就是一个部署在k8s集群中的服务,像其它服务一样部署既可。

下载yaml文件

wget https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml

修改deploy部分

    ...
    spec:
      containers:
      - name: kubernetes-dashboard
        # 从本地私有镜像库拉取,原镜像正常应该拉不下来
        image: 10.0.2.5:443/kubernetes-dashboard-amd64
        ports:
        # 简单起见,用非安全端口,这里只能是9090,应该是镜像只暴露了9090端口
        - containerPort: 9090
          protocol: TCP
        volumeMounts:
        # cert相关去掉
        - mountPath: /tmp
          name: tmp-volume
        livenessProbe:
          httpGet:
            # 改成 http
            scheme: HTTP
            path: /
            # 相应改成9090
            port: 9090
          initialDelaySeconds: 30
          timeoutSeconds: 30
      volumes:
      # cert相关去掉
      - name: tmp-volume
        emptyDir: {}
      serviceAccountName: kubernetes-dashboard
      # Comment the following tolerations if Dashboard must not be deployed on master
      tolerations:
      - key: node-role.kubernetes.io/master
        effect: NoSchedule

修改service部分

kind: Service
apiVersion: v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kube-system
spec:
  # 添加type参数,改为NodePort,对集群外暴露
  type: NodePort
  ports:
      # 服务监听端口,随意指定
    - port: 8080
      # 容器端口设为deployment里面的containerPort
      targetPort: 9090
      # 增加nodePort
      nodePort: 30001
  selector:
    k8s-app: kubernetes-dashboard

修改完毕,执行

kubectl apply -f kubernetes-dashboard.yaml

现在通过任意节点ipnodePort即可访问dashboard,如http://10.0.2.5:30001

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐