Kubernetes基本术语与架构

来源:互联网 发布:手机装修画图软件 编辑:程序博客网 时间:2024/05/17 08:35
1.node

被master管理的可以是物理机也可以是虚拟机,上面运行kubelet(用来启动和管理Pod)。
node上运行的服务有:kubelet、kube-proxy、docker deamon。
node的状态有running、pending、terminated。
通过kube-controller-manager管理nodes:集群内nodes信息同步和单个node生命周期管理。
配置文件/etc/kubenetes/kubelet,启动kubelet后可以自动向master注册,也可以手动管理node。

获取kubernetes集群中管理的nodes
[root@centos-master kubeguide]# kubectl get nodes
NAME            LABELS                                 STATUS    AGE
centos-master   kubernetes.io/hostname=centos-master   Ready     4d
centos-minion  kubernetes.io/hostname=centos-minion   Ready     4d

查看node状态



2.Pod

可以看作是容器的“豌豆荚”或LogicalHost,Pod内的container是紧耦合的,pod中的容器共享同一个主机名,可以互相通信、看到其他进程的PID,能够访问同一个IP和端口范围、共享Volumes。
使用yaml或json对node定义。pod生命周期是Replication Controller来管理的。

3.Label

Label用来给对象分组。Label是通过key-value方式在创建对象的时候附属在对象上的。其他对象可以通过Label Selector选择作用对象。Lebel也可以在对象创建后通过API来管理。
一个Pod可以定义多个Labels,可以把Lebel Selector看作SQL查询语句中的where条件查询。

4.Controller Manager

CM内部包含Replication Controller、Node Controller、ResourceQuota Controller、Namespace Controller、ServiceAccount Controller、Token Controller、Service Controller、Endpoint Controller。
定义Pod副本数量,自动创建、监控和启停pod,实现集群的高可用性。通过修改RC可以实现Rolling Update。
删除RC不会影响通过该RC创建的Pod。为了删除所有pod,可以先将relicas值设置为0然后更新该RC。也可以通过kubectl stop和delete一次性删除RC和RC控制的Pods。

5.Service

Service可以看作一组提供相同服务的Pod的对外访问接口。Service作用于哪些Pod通过Label Selector来定义。
Service定义yaml实例如下:
apiVersion: v1
kind: Service
metadata:
  name: frontend
  labels:
    name: frontend
spec:
  type: NodePort
  ports:
  - port: 80
    nodePort: 30001
  selector:
    name: frontend 
外部访问Service为集群外的客户端服务需要公共IP,可以通过Service中的NodePort和LoadBalancer来实现。
使用kubectl get endpoints命令可以看到frontend service的endpoints。
Endpoints即外部服务端访问service时访问的对应的cluster的后端端口,是cluster需要对外暴露的端口号。在service的定义文件中配置可以对外暴露多个端口。
每一个启动了frontend的pod都会打开80端口。
[root@centos-master kubeguide]# kubectl get endpoints
NAME           ENDPOINTS                                    AGE
frontend       172.17.0.10:80,172.17.0.7:80,172.17.0.8:80   3h
kubernetes     10.10.3.184:6443                             5d
redis-master   172.17.0.3:6379                              23h
redis-slave    172.17.0.3:6379,172.17.0.4:6379              21h

6.Volume

Volume是pod中能够被多个容器共享的目录,与pod的生命周期相同,与容器的生命周期不相关。即使容器停止或重启volume中的数据也不会丢失。
Volume提供的类型有:
  1. EmptyDir:临时空间,目前用户无法控制存储介质(即用户还无法设置存储在硬盘、SSD、还是基于内存的tmpfs上)。
  2. hostPath:在Pod上挂载宿主机的文件或目录。
  3. gcePersistentDisk:使用Google Compute Engine上永久磁盘上的文件。
  4. awsElasticBlockStore:使用AWS的EBS Volume。
  5. nfs:使用NFS提供的共享目录挂在到pod中。
  6. iscsi:使用iSCISI存储设备上的目录挂载到pod中。
  7. glusterfs:使用开源GlusterFS网络文件系统的目录挂载到pod中。
  8. rbd:Linux块设备共享存储(Rados Block Device)
  9. gitRepo:通过挂载一个空目录,并从GIT库clone一个git repository以供pod使用。
  10. secret:secret volume提供加密信息,通过tmfs实现,不会被持久化。
  11. persistentVolumeClaim:从PV(PersistentVolume)中申请所需空间,PV通常是网络存储,如GCE、AWS等。

7.Namespace

用于逻辑上划分不同项目、小组、用户组。Kubernetes集群启动后会有一个default分组。创建pod的时候可以指定属于那个namespace。
[root@centos-master kubeguide]# kubectl get namespaces
NAME      LABELS    STATUS    AGE
default   <none>    Active    5d
kubectl get pods命令如果不加任何参数的话只显示default namespace,可以通过--namespace=spacename方式查询spacename分组的pods。
使用namespace可以管理多租户,资源配额。

8.Annotation

Annotation是用户任意定义的附加信息,便于外部工具查找。

架构图

老版本中node被叫做minion。


API Server:操作资源对象的唯一入口。其他对象必须通过它提供的API操作资源数据。提供restful接口。
Controller Manager:集群内部的管控中心,故障检测,自动化恢复。
Scheduler:调度器,pod在集群node间的调度。
Kubelet:负责本node节点上的pod的增加、删除、监控、修改等全生命周期管理。内嵌Google的另外一个开源项目cAdvisor,实时监控docker上运行的容器的性能指标。实际调用API server的restful接口。
Proxy:Service的代理,kubectl proxy是API server的反向代理,kubernetes集群外部的客户端可以通过kubectl proxy来访问API server。

通过查看etcd中的目录结构也对kubernetes中的组件可见一斑。

[root@centos-master kubeguide]# etcdctl --endpointhttp://10.10.3.184:2379 ls /registry/
/registry/pods
/registry/events
/registry/minions
/registry/namespaces
/registry/ranges
/registry/serviceaccounts
/registry/services
/registry/controllers

1 0
原创粉丝点击