k8s配置dashboard v1.10.0

1.下载配置文件(有的时候链接不上,重复试几次就好了)

mkdir /data/k8s
cd /data/k8s
wget https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml

2.对配置文件进行修改

​ 在配置文件中的Dashboard Service部分下添加type: NodePort和nodePort: 30001,添加位置如下

vi /data/k8s/kubernetes-dashboard.yaml

在这里插入图片描述

3.修改镜像为国内镜像文件

registry.cn-hangzhou.aliyuncs.com/wzz/kubernetes-dashboard-amd64:v1.10.0

​ 在Dashboard Deployment中的image后面的内容改为上面的内容
在这里插入图片描述

4.应用配置文件

​ cd /data/k8s && kubectl apply -f kubernetes-dashboard.yaml

secret/kubernetes-dashboard-certs created 
serviceaccount/kubernetes-dashboard created
role.rbac.authorization.k8s.io/kubernetes-dashboard-minimal created
rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard-minimal created
deployment.apps/kubernetes-dashboard created service/kubernetes-dashboard created

5.查看pods

​ kubectl get pods -n kube-system

NAME                                            READY     STATUS              RESTARTS   AGE
coredns-78fcdf6894-m9kwr                        1/1       Running             1          20h
coredns-78fcdf6894-tgjn6                        1/1       Running             1          20h
etcd-inspur2.ops.haodf.bj1                      1/1       Running             1          20h
kube-apiserver-inspur2.ops.bds.bj1            1/1       Running             1          20h
kube-controller-manager-inspur2.ops.bds.bj1   1/1       Running             1          20h
kube-flannel-ds-amd64-d8vxk                     0/1       CrashLoopBackOff    40         20h
kube-flannel-ds-amd64-lh2jf                     1/1       Running             1          3h
kube-proxy-24gvj                                1/1       Running             1          20h
kube-proxy-n29ch                                1/1       Running             0          3h
kube-scheduler-inspur2.ops.bds.bj1            1/1       Running             1          20h
kubernetes-dashboard-767dc7d4d-8d5nf            0/1       ContainerCreating   0          12s

​ 此时还在拉取镜像之类的操作,等一会再此查看就会显示Runing,说明启动成功了

6.查看dashboard信息

​ kubectl describe svc kubernetes-dashboard -n kube-system

Name:                     kubernetes-dashboard
Namespace:                kube-system
Labels:                   k8s-app=kubernetes-dashboard
Annotations:              kubectl.kubernetes.io/last-applied-configuration:
                            {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"k8s-app":"kubernetes-dashboard"},"name":"kubernetes-dashboard"...
Selector:                 k8s-app=kubernetes-dashboard
Type:                     NodePort
IP:                       10.102.13.194
Port:                     <unset>  443/TCP
TargetPort:               8443/TCP
NodePort:                 <unset>  30001/TCP
Endpoints:                192.168.0.33:8443
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

7.获取nodeport

​ kubectl get service -n kube-system -o wide
在这里插入图片描述

8.创建admin user

​ cd /data/k8s/ && vi admin-user.yaml

​ 在文件中添加如下内容

apiVersion: v1
kind: ServiceAccount
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: admin
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: admin
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: admin
  namespace: kube-system

​ kubectl apply -f admin-user.yaml创建成功

9.获取token

kubectl describe serviceaccount admin -n kube-system
在这里插入图片描述
kubectl describe secret admin-token-2rddq -n kube-system (加粗部分与图上红框内容一致)

在这里插入图片描述

​ token部分保留,登录用

10.登录dashboard

​ 打开火狐浏览器网址输入: https://<主机地址,如192.168.0.108>:30001/

​ 第一次登录会报地址不安全,忽略就好了(用chrome可能麻烦点)

在这里插入图片描述

​ 点击令牌,输入刚才得到的token,点击登录就可以了

在这里插入图片描述

Logo

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

更多推荐