<转>Kubernetes Web UI搭建

本文介绍如何使用 Docker 私有库部署 Kubernetes Web UI,包括加载镜像、推送私有库、编辑配置文件等步骤,并展示了创建后的 Pods 和 Service 详细信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Kubernetes Web UI搭建

这节我以搭建Kubernetes Web UI(kubernetes-dashboard)来简要演示如何使用Docker私有库。

由于我的Kubernetes集群无法直接从gcr.io拉取kubernetes-dashboard的镜像,我事先下载了镜像文件并使用docker load命令加载镜像:

# docker load < kubernetes-dashboard-amd64_v1.1.0.tar.gz
# docker images
REPOSITORY                                        TAG                 IMAGE ID            CREATED             SIZE
registry                                          2                   c6c14b3960bd        3 days ago          33.28 MB
ubuntu                                            latest              42118e3df429        9 days ago          124.8 MB
hello-world                                       latest              c54a2cc56cbb        4 weeks ago         1.848 kB
172.28.80.11:5000/kubernetes-dashboard-amd64      v1.1.0              20b7531358be        5 weeks ago         58.52 MB
registry                                          2                   8ff6a4aae657        7 weeks ago         171.5 MB


我为加载的kubernetes-dashboard镜像打上私有库的标签并推送到私有库:

# docker tag 20b7531358be 192.168.169.125:5000/kubernetes-dashboard-amd64
# docker push 192.168.169.125:5000/kubernetes-dashboard-amd64


从Kubernetes官网获取了kubernetes-dashboard的配置文件https://rawgit.com/kubernetes/dashboard/master/src/deploy/kubernetes-dashboard.yaml,对其进行编辑如下:

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. # Copyright 2015 Google Inc. All Rights Reserved.  
  2. #  
  3. # Licensed under the Apache License, Version 2.0 (the "License");  
  4. # you may not use this file except in compliance with the License.  
  5. # You may obtain a copy of the License at  
  6. #  
  7. #     http://www.apache.org/licenses/LICENSE-2.0  
  8. #  
  9. # Unless required by applicable law or agreed to in writing, software  
  10. # distributed under the License is distributed on an "AS IS" BASIS,  
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
  12. # See the License for the specific language governing permissions and  
  13. # limitations under the License.  
  14.   
  15. # Configuration to deploy release version of the Dashboard UI.  
  16. #  
  17. # Example usage: kubectl create -f <this_file>  
  18.   
  19. kind: Deployment  
  20. apiVersion: extensions/v1beta1  
  21. metadata:  
  22.   labels:  
  23.     app: kubernetes-dashboard  
  24.     version: v1.1.0  
  25.   name: kubernetes-dashboard  
  26.   namespace: kube-system  
  27. spec:  
  28.   replicas: 1  
  29.   selector:  
  30.     matchLabels:  
  31.       app: kubernetes-dashboard  
  32.   template:  
  33.     metadata:  
  34.       labels:  
  35.         app: kubernetes-dashboard  
  36.     spec:  
  37.       containers:  
  38.       - name: kubernetes-dashboard  
  39.         image: 192.168.169.125:5000/kubernetes-dashboard-amd64  
  40.         imagePullPolicy: Always  
  41.         ports:  
  42.         - containerPort: 9090  
  43.           protocol: TCP  
  44.         args:  
  45.           # Uncomment the following line to manually specify Kubernetes API server Host  
  46.           # If not specified, Dashboard will attempt to auto discover the API server and connect  
  47.           # to it. Uncomment only if the default does not work.  
  48.           - --apiserver-host=192.168.169.120:8080  
  49.         livenessProbe:  
  50.           httpGet:  
  51.             path: /  
  52.             port: 9090  
  53.           initialDelaySeconds: 30  
  54.           timeoutSeconds: 30  
  55. ---  
  56. kind: Service  
  57. apiVersion: v1  
  58. metadata:  
  59.   labels:  
  60.     app: kubernetes-dashboard  
  61.   name: kubernetes-dashboard  
  62.   namespace: kube-system  
  63. spec:  
  64.   type: NodePort  
  65.   ports:  
  66.   - port: 80  
  67.     targetPort: 9090  
  68.   selector:  
  69.     app: kubernetes-dashboard  

尤其要注意:1 创建的Pods所要拉取的镜像是Docker私有库的192.168.169.125:5000/kubernetes-dashboard-adm64; 2 apiserver-host参数是192.168.169.120:8080,即Kubernetes Master节点的aipserver服务地址。

修改完kubernetes-dashboard.yaml后保存到Kubernetes Master节点192.168.169.120节点上,在该节点上用kubectl create命令创建kubernetes-dashboard:

# kubectl create -f kubernetes-dashboard.yaml 


创建完成后,查看Pods和Service的详细信息:

# kubectl get pods --all-namespaces
NAMESPACE     NAME                                    READY     STATUS    RESTARTS   AGE
default       nginx                                   1/1       Running   0          3h
kube-system   kubernetes-dashboard-4164430742-lqhcg   1/1       Running   0          2h


# kubectl describe pods/kubernetes-dashboard-4164430742-lqhcg --namespace="kube-system"
Name:        kubernetes-dashboard-4164430742-lqhcg
Namespace:    kube-system
Node:        192.168.169.124/192.168.169.124
Start Time:    Mon, 01 Aug 2016 16:12:02 +0800
Labels:        app=kubernetes-dashboard,pod-template-hash=4164430742
Status:        Running
IP:        172.17.17.3
Controllers:    ReplicaSet/kubernetes-dashboard-4164430742
Containers:
  kubernetes-dashboard:
    Container ID:    docker://40ab377c5b8a333487f251547e5de51af63570c31f9ba05fe3030a02cbb3660c
    Image:        192.168.169.125:5000/kubernetes-dashboard-amd64
    Image ID:        docker://sha256:20b7531358be693a34eafdedee2954f381a95db469457667afd4ceeb7146cd1f
    Port:        9090/TCP
    Args:
      --apiserver-host=192.168.169.120:8080
    QoS Tier:
      cpu:        BestEffort
      memory:        BestEffort
    State:        Running
      Started:        Mon, 01 Aug 2016 16:12:03 +0800
    Ready:        True
    Restart Count:    0
    Liveness:        http-get http://:9090/ delay=30s timeout=30s period=10s #success=1 #failure=3
    Environment Variables:
Conditions:
  Type        Status
  Ready     True 
No volumes.
No events.


# kubectl describe service/kubernetes-dashboard --namespace="kube-system"
Name:            kubernetes-dashboard
Namespace:        kube-system
Labels:            app=kubernetes-dashboard
Selector:        app=kubernetes-dashboard
Type:            NodePort
IP:            10.254.213.209
Port:            <unset>    80/TCP
NodePort:        <unset>    31482/TCP
Endpoints:        172.17.17.3:9090
Session Affinity:    None
No events.


从kubernetes-dashboard的service详细信息可以看到,该service绑定到了Node节点的31482端口上。现在,通过浏览器访问该端口就能看到Kubernetes的Web UI:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值