一、简介

  1、环境

  环境还是前面的环境

  2、Kubernetes Dashboard web界面

    kubernetes dashboard (仪表盘)是一个将通用的基于web的监控和操作界面加入kubernetes的项目

二、开始部署yaml配置文件

  1、创建/编辑deployment

[root@master k8s]# vim dashboard-deployment.yaml 

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
# Keep the name in sync with image version and
# gce/coreos/kube-manifests/addons/dashboard counterparts
  name: kubernetes-dashboard-latest
  namespace: kube-system
spec:                                      #---定义pod属性
  replicas: 1
  template:
    metadata:
      labels:
        k8s-app: kubernetes-dashboard
        version: latest
        kubernetes.io/cluster-service: "true"
    spec:
      containers:
      - name: kubernetes-dashboard
        image: docker.io/bestwu/kubernetes-dashboard-amd64:v1.6.3   #---镜像源,下面章节3上传的镜像
        imagePullPolicy: IfNotPresent
        resources:
          # keep request = limit to keep this container in guaranteed class
          limits:                              #---关于pod使用的cpu和内存硬件资源做限制
            cpu: 100m
            memory: 50Mi
          requests:
            cpu: 100m
            memory: 50Mi
        ports:
        - containerPort: 9090
        args:
        - --apiserver-host=http://192.168.216.51:8080      #这里填写自己的apiserver服务器地址及端口
       # - --apiserver-host=http://192.168.216.51:8080
        livenessProbe:
          httpGet:
            path: /
            port: 9090
          initialDelaySeconds: 30
          timeoutSeconds: 30

  2、编辑服务dashboard-service.yaml 

[root@master k8s]# vim dashboard-service.yaml 

apiVersion: v1
kind: Service
metadata:
  name: kubernetes-dashboard    #---这个要和上面deployment中定义的一样
  namespace: kube-system       #---同样和上面deployment定义一样
  labels:
    k8s-app: kubernetes-dashboard
    kubernetes.io/cluster-service: "true"
spec:
  selector:
    k8s-app: kubernetes-dashboard
  ports:
  - port: 80
    targetPort: 9090

   说明:service的三种端口

    port:service暴露在集群ip上的端口,提供给集群内部客户访问service入口

    nodePort:是k8s提供给集群外部客户访问service入口的一种方式

    targetPort:targetPort是pod中容器实例上的端口,从port和nodePort上到来的数据最终经过kube-proxy流入到后端pod的targetport上进入容器

 

  3、上传镜像到node节点上

    自行下载这些镜像然后导入,或者在线下载镜像

[root@node2 k8s]# ll 
total 1497532
-rw-r--r-- 1 root root 139341824 Jan 16  2019 docker.io-bestwu-kubernetes-dashboard-amd64-zh.tar
-rw-r--r-- 1 root root  86496256 Jan 16  2019 kubernetes-dashboard-amd64.tar #另外一个版本,可以先不上传
-rw-r--r-- 1 root root 218623488 Jan 16  2019 pod-infrastructure.tar
[root@node2 k8s]# pwd
/root/k8s

    下载后导入,之前已经下载过pod-infrastructure

docker load -i docker.io-bestwu-kubernetes-dashboard-amd64-zh.tar
docker load -i kubernetes-dashboard-amd64.tar 

 

  4、启动deployment和service

[root@master k8s]# cd /etc/kubernetes/yaml/
[root@master kubernetes]# kubectl create -f /etc/kubernetes/yaml/dashboard-deployment.yaml 
deployment "kubernetes-dashboard-latest" created
[root@master kubernetes]# kubectl create -f /etc/kubernetes/yaml/dashboard-service.yaml 
service "kubernetes-dashboard" created

  5、查看deployment及servcie

    因为定义了namespace所以需要加上–all-namespaces才可以显示,而默认是namespaces=default的deployment

[root@master ~]# kubectl get deployment --all-namespaces
NAMESPACE     NAME                          DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
kube-system   kubernetes-dashboard-latest   1         1         1            1           23m
[root@master ~]# kubectl get svc --all-namespaces
NAMESPACE     NAME                   CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
default       kubernetes             10.254.0.1     <none>        443/TCP        13d
default       nginx                  10.254.8.125   <nodes>       80:31011/TCP   8d
kube-system   kubernetes-dashboard   10.254.32.13   <none>        80/TCP         23m
[root@master ~]# 

  6、销毁web界面

  kubectl delete deployment kubernetes-dashboard-latest--namespace=kube-system

  kubectl delete svc kubernetes-dashboard--namespace=kube-system

 

  

三、web验证

  1、登陆web端

    http://192.168.216.51:8080/ui

  2、run一个nginx查看这个容器

[root@master ~]# kubectl run nginx --image=docker.io/nginx --replicas=1 --port=9000
deployment "nginx" created
[root@master ~]# kubectl get pod
NAME                     READY     STATUS    RESTARTS   AGE
nginx-2187705812-n5wsr   1/1       Running   0          37s
nginx-2187705812-zngv0   1/1       Running   0          25s

 

 kubernetes系列文章:

Kubernetes1-K8s的简单介绍

Kubernetes2-K8s的集群部署

Kubernetes3-kubectl管理Kubernetes容器平台-1

Kubernetes3-kubectl管理Kubernetes容器平台-2

参考:互联网内容

转载请注明出处:https://www.cnblogs.com/zhangxingeng/p/11842258.html

版权声明:本文为zhangxingeng原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/zhangxingeng/p/11842258.html