k8s dashboard安装与访问

本次部署的环境为centos7.6,k8s和dashboard部署步骤说明如下

  1. k8s安装
      部署dashboard前提是k8s环境已安装完成,本次部署的节点数:一个master(192.168.43.191)和一个node(192.168.43.184)节点,安装步骤参考博客
    CentOS7安装k8s
  2. dashboard部署
    2.1 编辑配置文件
    通过vim命令,打开配置文件,vim kubernetes-dashboard.yaml,编辑文件内容如下:
kind: Deployment 
apiVersion: extensions/v1beta1 
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 
      # Comment the following annotation if Dashboard must not be deployed on master 
      annotations: 
        scheduler.alpha.kubernetes.io/tolerations: | 
          [ 
            { 
              "key": "dedicated", 
              "operator": "Equal", 
              "value": "master", 
              "effect": "NoSchedule" 
            } 
          ] 
    spec: 
      containers: 
      - name: kubernetes-dashboard 
        image: docker.io/siriuszg/kubernetes-dashboard-amd64:v1.5.1      #默认的镜像是使用google的,这里改成内网 ,可通过docker hub网页查找镜像及版本
        imagePullPolicy: Always 
        ports: 
        - containerPort: 9090 
          protocol: TCP 
        args: 
          # Uncomment the following line to manually specify Kubernetes API server Host 
          # If not specified, Dashboard will attempt to auto discover the API server and connect 
          # to it. Uncomment only if the default does not work. 
          - --apiserver-host=http://192.168.43.191:8080    #注意这里是api的地址 
        livenessProbe: 
          httpGet: 
            path: / 
            port: 9090 
          initialDelaySeconds: 30 
          timeoutSeconds: 30 
--- 
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 

其中,image镜像值可通过docker hub界面或者docker search命令查询搜索,获取image路径和版本号。
2.2 创建dashboard容器
  进入kubernetes-dashboard.yaml文件所在目录,执行如下命令,实现dashboard容器创建。
(1)通过如下命令,实现dashboard pod创建
kubectl create -f kubernetes-dashboard.yaml
(2)若kubernetes-dashboard.yaml配置文件内容修改,通过执行如下命令,将原配置删除,重新执行kubectl create创建容器
kubectl delete -f kubernetes-dashboard.yaml
(3)查看pods,确认dashboard的pod已经删除
kubectl get pods --all-namespaces
在linux shell界面,执行命令如下所示

[root@bogon ~]# kubectl delete -f kubernetes-dashboard.yaml
deployment "kubernetes-dashboard" deleted
service "kubernetes-dashboard" deleted
[root@bogon ~]# kubectl create -f kubernetes-dashboard.yaml #重新加载配置,创建dashboard pod
deployment "kubernetes-dashboard" created
service "kubernetes-dashboard" created
[root@bogon ~]# kubectl get pods --all-namespaces #查看pods
[root@bogon ~]# kubectl logs -f kubernetes-dashboard-821076405-xr097 --namespace=kube-system #查看pod日志
[root@bogon ~]# kubectl describe pod kubernetes-dashboard-821076405-xr097 --namespace=kube-system #查看pod详情
  1. dashboard访问
      首先通过shell命令查找dashboard的IP和端口,在dashboard部署节点,打开浏览器,输入IP:端口访问服务,实现dashboard访问。
    (1)查看dashboard被k8s分配到了哪一台机器上,IP
    kubectl get pods --all-namespaces -o wide
    (2)接着执行如下命令,查看dashboard的集群内部IP和访问端口
    kubectl get services --all-namespaces
    通过上述步骤,找到服务的IP、端口
    k8s dashboard安装与访问_第1张图片
    image.png

    (3)在浏览器输入IP端口,实现服务访问
    k8s dashboard安装与访问_第2张图片
    image.png
  2. 问题解决
    (1)使用k8s命令(kubectl create ...)创建容器一直处于ContainerCreating状态,查看容器详情,报错:
    Back-off pulling image "registry.access.redhat.com/rhel7/pod-infrastructure:latest
    参考如下博客将问题解决:
    Back-off pulling image "registry.access.redhat.com/rhel7/pod-infrastructure:latest
    (2)
    参考如下博客,解决Centos7下Kubernetes(k8s)部署好之后无法访问dashboard问题
    解决Centos7下Kubernetes(k8s)部署好之后无法访问dashboard

你可能感兴趣的:(k8s dashboard安装与访问)