Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4516264
  • 博文数量: 252
  • 博客积分: 5347
  • 博客等级: 大校
  • 技术积分: 13838
  • 用 户 组: 普通用户
  • 注册时间: 2009-09-30 10:13
文章分类
文章存档

2022年(12)

2017年(11)

2016年(7)

2015年(14)

2014年(20)

2012年(9)

2011年(20)

2010年(153)

2009年(6)

分类: 云计算

2017-08-31 17:30:46

  在master节点上创建dashboard,在创建dashborad的时候,会在node节点上pull一个kubernetes-dashboard-amd64的镜像,然后在node节点上使用该镜像创建一个container

1.1 查看namespace 

使用kubectl get namespace命令可以获取到,这个版本的kubernets默认有kube-system的namespace,如果没有的话,可以使用下面的脚本进行创建,

kubernetes-namespace.jason文件的内容如下:

{

  "kind": "Namespace",

  "apiVersion": "v1",

  "metadata": {

    "name": "kube-system"

  }

}

 使用kubectl create -f kubernetes-namespace.jason创建kube-system命名空间。

1.2 dashboard的搭建

1.2.1 dashboard的搭建

创建kubernetes-dashboard.yaml文件,该文件用于创建dashboard

点击(此处)折叠或打开

  1. cat kubernetes-dashboard.yaml
  2. # Copyright 2015 Google Inc. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.

  15. # Configuration to deploy release version of the Dashboard UI.
  16. #
  17. # Example usage: kubectl create -f <this_file>

  18. kind: Deployment
  19. apiVersion: extensions/v1beta1
  20. metadata:
  21.   labels:
  22.     app: kubernetes-dashboard
  23.     version: v1.1.1
  24.   name: kubernetes-dashboard
  25.   namespace: kube-system
  26. spec:
  27.   replicas: 1
  28.   selector:
  29.     matchLabels:
  30.       app: kubernetes-dashboard
  31.   template:
  32.     metadata:
  33.       labels:
  34.         app: kubernetes-dashboard
  35.     spec:
  36.       containers:
  37.       - name: kubernetes-dashboard
  38.         image: gcr.io/google_containers/kubernetes-dashboard-amd64:v1.6.0
  39.         imagePullPolicy: IfNotPresent
  40.         ports:
  41.         - containerPort: 9090
  42.           protocol: TCP
  43.         args:
  44.           # Uncomment the following line to manually specify Kubernetes API server Host
  45.           # If not specified, Dashboard will attempt to auto discover the API server and connect
  46.           # to it. Uncomment only if the default does not work.
  47.         - --apiserver-host=http://10.9.178.109:8080 ## 请修改为自己的kebu-apiserver
  48.         livenessProbe:
  49.           httpGet:
  50.             path: /
  51.             port: 9090
  52.           initialDelaySeconds: 30
  53.           timeoutSeconds: 30
  54. ---
  55. kind: Service
  56. apiVersion: v1
  57. metadata:
  58.   labels:
  59.     app: kubernetes-dashboard
  60.   name: kubernetes-dashboard
  61.   namespace: kube-system
  62. spec:
  63.   type: NodePort
  64.   ports:
  65.   - port: 80
  66.     targetPort: 9090
  67.   selector:
  68. app: kubernetes-dashboard

上面文件中image: gcr.io/google_containers/kubernetes-dashboard-amd64:v1.6.0 这里使用的从google下载的镜像,生成container,如果被墙了,可以使用国内的镜像库下载后使用,这里使用有两种方法:第一种:下载下来后,配置kubernetes-dashboard.yaml文件中的 imagespull下来的name,第二种:是把下载下来的image docker taggcr.io/google_containers/kubernetes-dashboard-amd64 这样就不需要进行专门的指定。

例如下面的方法:

docker pull registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0

docker tag registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0 gcr.io/google_containers/pause-amd64:3.0

  上面的文件中需要指定- --apiserver-hostmaster节点的ip地址。

2.2.2 创建kubernetes-dashboard

根据上面的文件使用kubectl create -f kubernetes-dashboard.yaml 命令创建dashboard

[root@10-9-178-109 k8s]# kubectl create -f kubernetes-dashboard.yaml

deployment "kubernetes-dashboard" created

service "kubernetes-dashboard" created

创建完成后使用kubectl get pod --namespace="kube-system" 查看器状态,

使用kubectl describe pods kubernetes-dashboard-2098749498-w3vl9  --namespace=kube-system命令可以查看运行的状态:


点击(此处)折叠或打开

  1. Name: kubernetes-dashboard-2098749498-w3vl9
  2. Namespace: kube-system
  3. Node: 10.9.106.37/10.9.106.37
  4. Start Time: Mon, 07 Aug 2017 11:09:22 +0800
  5. Labels: app=kubernetes-dashboard
  6.                    pod-template-hash=2098749498
  7. Annotations: kubernetes.io/created-by={"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ReplicaSet","namespace":"kube-system","name":"kubernetes-dashboard-2098749498","uid":"cfa92117-7b1d-11e7-a...
  8. Status: Running
  9. IP: 192.168.72.2
  10. Created By: ReplicaSet/kubernetes-dashboard-2098749498
  11. Controlled By: ReplicaSet/kubernetes-dashboard-2098749498
  12. Containers:
  13.   kubernetes-dashboard:
  14.     Container ID: docker://13da640b3958032ae1565fbeed51003f906537206f191f514ac490492d0e9f79
  15.     Image: gcr.io/google_containers/kubernetes-dashboard-amd64:v1.6.0
  16.     Image ID: docker://sha256:416701f962f2f18e393d63e3840f7a3cda6da144e09692ccbf780f7f8bd0ef3f
  17.     Port: 9090/TCP
  18.     Args:
  19.       --apiserver-host=
  20.     State: Running
  21.       Started: Mon, 07 Aug 2017 11:09:23 +0800
  22.     Ready: True
  23.     Restart Count: 0
  24.     Liveness: http-get delay=30s timeout=30s period=10s #success=1 #failure=3
  25.     Environment:
  26.     Mounts:
  27. Conditions:
  28.   Type Status
  29.   Initialized True
  30.   Ready True
  31. PodScheduled True
  32. Volumes:
  33. QoS Class: BestEffort
  34. Node-Selectors:
  35. Tolerations:
  36. Events:
  37.   FirstSeen LastSeen Count From SubObjectPath Type Reason Message
  38.   --------- -------- ----- ---- ------------- -------- ------ -------
  39.   2m 2m 1 default-scheduler Normal Scheduled Successfully assigned kubernetes-dashboard-2098749498-w3vl9 to 10.9.106.37
  40.   2m 2m 1 kubelet, 10.9.106.37 spec.containers{kubernetes-dashboard} Normal Pulled Container image "gcr.io/google_containers/kubernetes-dashboard-amd64:v1.6.0" already present on machine
  41.   2m 2m 1 kubelet, 10.9.106.37 spec.containers{kubernetes-dashboard} Normal Created Created container
  42.   2m 2m 1 kubelet, 10.9.106.37 spec.containers{kubernetes-dashboard} Normal Started Started container
  43.   2m 1m 6 kubelet, 10.9.106.37 Warning MissingClusterDNS kubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst


创建成功后在node节点,可以看到启动了两个container 


使用kubectl describe service  kubernetes-dashboard  --namespace="kube-system"命令可以查看到node节点的信息,其中192.168.72.2IP地址为


在node节点上使用gcr.io/google_containers/pause-amd64:3.0镜像 启动的container的ip地址为 192.168.72.2,这个就是基础镜像的ip地址,根据etcd和flanneld分配的,在master的节点上可以ping通这个ip地址,这里其实相当于在两台host上,使用etcd和flanneld搭建了一个跨主机的vxlan的overlay网络。使用pause-amd64镜像生成的container,作为基础镜像,在node节点上其余的container使用docker的 container网络模型共享网络。

node节点上docker inspect 13da640b3958 可以看到kubernetes-dashboard-amd64的网络模式为container,这里的containerid192.178.72.2container

保证在master节点上能pingnode节点上的pause-amd64生成的container后,可以在浏览器重输入:master public ip + 8080/ui 例如:后,可以出现久违的kubernetes的页面信息。



阅读(6091) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~