kubernetes(25):安装部署Dashboard

k8s安装部署Dashboard

https://blog.csdn.net/cyfblog/article/details/97761406

Dashboard 是基于网页的 Kubernetes 用户界面。您可以使用 Dashboard 将容器应用部署到 Kubernetes 集群中,也可以对容器应用排错,还能管理集群本身及其附属资源。您可以使用 Dashboard 获取运行在集群中的应用的概览信息,也可以创建或者修改 Kubernetes 资源(如 Deployment,Job,DaemonSet 等等)。例如,您可以对 Deployment 实现弹性伸缩、发起滚动升级、重启 Pod 或者使用向导创建新的应用。

 

1  获取kubernetes-dashboard.yaml文件

https://github.com/kubernetes/dashboard

wget https://raw.githubusercontent.com/kubernetes/dashboard/master/aio/deploy/recommended/kubernetes-dashboard.yaml

 

 

2 修改kubernetes-dashboard.yaml文件

#修改镜像地址
      - name: kubernetes-dashboard
        #image: k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.1
        image: registry.cn-hangzhou.aliyuncs.com/google_containers/kubernetes-dashboard-amd64:v1.10.1
#增加对外端口映射
spec:
  type: NodePort    # 新增
  ports:
    - port: 443
      targetPort: 8443
      nodePort: 30080 #新增

 

 

3  启动Dashboard

kubectl create -f kubernetes-dashboard.yaml 

 

4  登陆页面

 

 

 

5  创建服务账号和集群角色绑定配置文件

# vim dashboard-adminuser.yaml
---
apiVersion: v1
kind: ServiceAccount
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard-admin
  namespace: kube-system

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

 

 

6  创建用户和角色绑定

kubectl apply -f dashboard-adminuser.yaml

 

7  查看 Token

[root@k8s-master k8s]# kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep kubernetes-dashboard-admin-token | awk '{print $1}')
Name:         kubernetes-dashboard-admin-token-sr689
Namespace:    kube-system
Labels:       <none>
Annotations:  kubernetes.io/service-account.name: kubernetes-dashboard-admin
              kubernetes.io/service-account.uid: eb9dee83-0230-48be-9353-cc898f26b677

Type:  kubernetes.io/service-account-token

Data
====
ca.crt:     1025 bytes
namespace:  11 bytes
token:      eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJrdWJlcm5ldGVzLWRhc2hib2FyZC1hZG1pbi10b2tlbi1zcjY4OSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJrdWJlcm5ldGVzLWRhc2hib2FyZC1hZG1pbiIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6ImViOWRlZTgzLTAyMzAtNDhiZS05MzUzLWNjODk4ZjI2YjY3NyIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDprdWJlLXN5c3RlbTprdWJlcm5ldGVzLWRhc2hib2FyZC1hZG1pbiJ9.WxZvNL3APtwx6dAO6Kg0IAKcoiBbZUVI2aXuioFcl3jXaY5RTxJWmBOhTia3-tZOcmPqvuU_SvJRyftEWFCQk46ASP-vvF3RTMkGlbfo2syBiIlcAsjQYDobm8FDXjn4J4UmtaMbepQGsGpuFJjipi2mcYZADwmoN6YzBYG2t3E7iJm0BVWvFA_AGWI1LFBDxsWghaFfAx3tcEFqNUTiLrZm7-IR3GxlbCgXhwwPsdFiPxH5hY57qoxsO8cgQbVteD3izqBTeM-xdexwhvacYE5Kh3O6IS5mrrLuaJWw_yyc4qx-BHoa6QFrdtXYID5JSx9an-XinLuvXRNzEB6G1w
[root@k8s-master k8s]#

 

 

8 登陆

选择令牌,输入token

 

 

 

 

 

 

 

 

9 利用dashboard对服务进行扩容

我们之前部署了Nginx服务

 

 

 

 

 

很快就扩容完成了

 

 

 

 

 

 

 

10 利用dashboard对服务进行滚动升级

我们的Nginx1.15版本,升级到最新版

 

 

 

 

 

 

 

 

我们更想之后滚动升级,直到成为最新版本 1.17.3

[root@k8s-master k8s]# kubectl get podsNAME                                READY   STATUS    RESTARTS   AGE
nginx-deployment-59bf58fcb5-7tmst   1/1     Running   0          17h
nginx-deployment-59bf58fcb5-dmv4n   1/1     Running   0          20s
nginx-deployment-59bf58fcb5-gxrwd   1/1     Running   0          20s
nginx-deployment-59bf58fcb5-hjq6c   1/1     Running   0          17h
nginx-deployment-59bf58fcb5-hwrx6   1/1     Running   0          20s
[root@k8s-master k8s]#
[root@k8s-master k8s]#
[root@k8s-master k8s]#
[root@k8s-master k8s]# kubectl get pods
NAME                                READY   STATUS              RESTARTS   AGE
nginx-deployment-59bf58fcb5-7tmst   1/1     Running             0          17h
nginx-deployment-59bf58fcb5-dmv4n   1/1     Terminating         0          3m5s
nginx-deployment-59bf58fcb5-hjq6c   1/1     Running             0          17h
nginx-deployment-59bf58fcb5-hwrx6   1/1     Terminating         0          3m5s
nginx-deployment-84cddf955f-4r2mx   1/1     Running             0          8s
nginx-deployment-84cddf955f-pfzhr   0/1     ContainerCreating   0          1s
nginx-deployment-84cddf955f-q6xc5   1/1     Running             0          8s
nginx-deployment-84cddf955f-txfkk   0/1     ContainerCreating   0          2s
[root@k8s-master k8s]# kubectl get pods
NAME                                READY   STATUS              RESTARTS   AGE
nginx-deployment-59bf58fcb5-7tmst   0/1     Terminating         0          17h
nginx-deployment-59bf58fcb5-hjq6c   1/1     Terminating         0          17h
nginx-deployment-84cddf955f-4r2mx   1/1     Running             0          14s
nginx-deployment-84cddf955f-8c6pz   0/1     ContainerCreating   0          3s
nginx-deployment-84cddf955f-pfzhr   1/1     Running             0          7s
nginx-deployment-84cddf955f-q6xc5   1/1     Running             0          14s
nginx-deployment-84cddf955f-txfkk   1/1     Running             0          8s
[root@k8s-master k8s]# kubectl get pods
NAME                                READY   STATUS        RESTARTS   AGE
nginx-deployment-59bf58fcb5-7tmst   0/1     Terminating   0          17h
nginx-deployment-59bf58fcb5-hjq6c   0/1     Terminating   0          17h
nginx-deployment-84cddf955f-4r2mx   1/1     Running       0          22s
nginx-deployment-84cddf955f-8c6pz   1/1     Running       0          11s
nginx-deployment-84cddf955f-pfzhr   1/1     Running       0          15s
nginx-deployment-84cddf955f-q6xc5   1/1     Running       0          22s
nginx-deployment-84cddf955f-txfkk   1/1     Running       0          16s
[root@k8s-master k8s]# kubectl get pods
NAME                                READY   STATUS              RESTARTS   AGE
nginx-deployment-84cddf955f-4r2mx   1/1     Running             0          28s
nginx-deployment-84cddf955f-8c6pz   1/1     Running             0          17s
nginx-deployment-84cddf955f-9hq97   0/1     ContainerCreating   0          2s
nginx-deployment-84cddf955f-pfzhr   1/1     Running             0          21s
nginx-deployment-84cddf955f-q6xc5   1/1     Running             0          28s
nginx-deployment-84cddf955f-txfkk   1/1     Running             0          22s
[root@k8s-master k8s]# kubectl get pods -o wide
NAME                                READY   STATUS    RESTARTS   AGE   IP            NODE         NOMINATED NODE   READINESSGATES
nginx-deployment-84cddf955f-4r2mx   1/1     Running   0          50s   10.254.1.39   k8s-node-1   <none>           <none>
nginx-deployment-84cddf955f-8c6pz   1/1     Running   0          39s   10.254.1.41   k8s-node-1   <none>           <none>
nginx-deployment-84cddf955f-9hq97   1/1     Running   0          24s   10.254.2.36   k8s-node-2   <none>           <none>
nginx-deployment-84cddf955f-pfzhr   1/1     Running   0          43s   10.254.2.35   k8s-node-2   <none>           <none>
nginx-deployment-84cddf955f-q6xc5   1/1     Running   0          50s   10.254.2.34   k8s-node-2   <none>           <none>
nginx-deployment-84cddf955f-txfkk   1/1     Running   0          44s   10.254.1.40   k8s-node-1   <none>           <none>
[root@k8s-master k8s]# curl -I 10.254.1.41
HTTP/1.1 200 OK
Server: nginx/1.17.3
Date: Fri, 30 Aug 2019 02:35:34 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 13 Aug 2019 08:50:00 GMT
Connection: keep-alive
ETag: "5d5279b8-264"
Accept-Ranges: bytes

[root@k8s-master k8s]#

 

posted on 2019-10-15 09:53  光阴8023  阅读(628)  评论(0编辑  收藏  举报