容器之间通讯方式\与pod关系
1.概述
k8s里面容器是存在于pod里面的,所以容器之间通讯,一般分为三种类型:
1. pod内部容器之间
2. pod 与 pod 容器之间
3. pod 访问service服务
(1) pod内部容器之间
k8s pod内部容器是共享网络空间的,所以容器直接可以使用localhost访问其他容器。
k8s 在启动容器的时候会先启动一个pause容器,这个容器就是实现这个功能的。
(2) pod 与 pod容器之间
a. 两个pod在一台主机上面
docker默认的docker网桥互连容器
b. 两个pod不在同一个主机上面
k8s官方推荐的是使用flannel组建一个大二层扁平网络,pod的ip分配由flannel统一分配,通讯过程也是走flannel的网桥
(3) pod访问service服务
Service分配的ip叫cluster ip是一个虚拟ip(相对固定,除非删除service),这个ip只能在k8s集群内部使用,如果service需要对外提供,只能使用Nodeport方式映射到主机上,使用主机的ip和端口对外提供服务
2. pod与容器区别
pod是k8s的最小单元,容器包含在pod中,一个pod中有一个pause容器和若干个业务容器,而容器就是单独的一个容器,简而言之,pod是一组容器,而容器单指一个容器
3.pod 配置管理
Name: task-pv-pod
Namespace: default // 没有指定namespace的就是default
Node: docker-for-desktop/192.168.65.3 // Pod所在的节点
Start Time: Mon, 08 Jul 2019 14:05:52 +0800 // pod启动的时间
Labels: <none> // 说明没有设置标签
Annotations: kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"name":"task-pv-pod","namespace":"default"},"spec":{"containers":[{"image":"nginx","name":... // 注释信息
Status: Running // pod的状态
IP: 10.1.0.103 // pod的集群ip
Containers: // 其中包含的容器
task-pv-container:
Container ID: docker://3e9a2ee6b0a13ccee534ec3ffe781adcbff42a7f1851d57e3b374a047a654590
Image: nginx // 容器镜像名称
Image ID: docker-pullable://nginx@sha256:96fb261b66270b900ea5a2c17a26abbfabe95506e73c3a3c65869a6dbe83223a
Port: 80/TCP
Host Port: 0/TCP
State: Running
Started: Mon, 08 Jul 2019 14:05:58 +0800
Ready: True
Restart Count: 0
Environment: <none>
Mounts: // 这个容器挂载的两个volume
/usr/share/nginx/html from task-pv-storage (rw)
/var/run/secrets/kubernetes.io/serviceaccount from default-token-tw8wk (ro)
Conditions:
Type Status
Initialized True
Ready True
PodScheduled True
Volumes:
task-pv-storage: // 挂载的数据卷
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace) // 这个数据卷是共享持久卷
ClaimName: task-pv-claim // 使用的声明
ReadOnly: false // 数据卷是否只读
default-token-tw8wk:
Type: Secret (a volume populated by a Secret) // 这个数据卷是保存密钥
SecretName: default-token-tw8wk
Optional: false
QoS Class: BestEffort // Qos的三个级别,Guaranteed/Burstable/BestEffort,分别对pod的资源限制从严到弱
Node-Selectors: <none> // pod是可以选择部署在哪个node上的,比如部署在有ssd的node上。
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s // 节点亲和性,它使得pod能有倾向性地分配到不同节点上。
node.kubernetes.io/unreachable:NoExecute for 300s
Events: // 这个pod发生的一些事件
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 21s default-scheduler Successfully assigned task-pv-pod to docker-for-desktop
Normal SuccessfulMountVolume 20s kubelet, docker-for-desktop MountVolume.SetUp succeeded for volume "task-pv-volume"
Normal SuccessfulMountVolume 20s kubelet, docker-for-desktop MountVolume.SetUp succeeded for volume "default-token-tw8wk"
Normal Pulling 19s kubelet, docker-for-desktop pulling image "nginx"
Normal Pulled 15s kubelet, docker-for-desktop Successfully pulled image "nginx"
Normal Created 15s kubelet, docker-for-desktop Created container
Normal Started 14s kubelet, docker-for-desktop Started container
有的时候我们可能会忘记了我们启动的pod的yaml配置文件地址,我们可以通过kubectl get pod task-pv-pod -o=yaml
命令来获取某个已经启动的 pod 的配置文件,这里的配置文件会比我们配置的配置项全很多,因为我们写配置文件的时候,很多配置项没有设置实际上就是使用默认的配置值来实现。
kubectl get pod task-pv-pod -o=yaml
apiVersion: v1
kind: Pod
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"name":"task-pv-pod","namespace":"default"},"spec":{"containers":[{"image":"nginx","name":"task-pv-container","ports":[{"containerPort":80,"name":"http-server"}],"volumeMounts":[{"mountPath":"/usr/share/nginx/html","name":"task-pv-storage"}]}],"volumes":[{"name":"task-pv-storage","persistentVolumeClaim":{"claimName":"task-pv-claim"}}]}}
creationTimestamp: 2019-07-08T06:05:51Z
name: task-pv-pod
namespace: default
resourceVersion: "1439249"
selfLink: /api/v1/namespaces/default/pods/task-pv-pod
uid: 7090642e-a146-11e9-89ff-025000000001
spec:
containers:
- image: nginx
imagePullPolicy: Always
name: task-pv-container
ports:
- containerPort: 80
name: http-server
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /usr/share/nginx/html
name: task-pv-storage
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-tw8wk
readOnly: true
dnsPolicy: ClusterFirst
nodeName: docker-for-desktop
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
serviceAccount: default
serviceAccountName: default
terminationGracePeriodSeconds: 30
tolerations:
- effect: NoExecute
key: node.kubernetes.io/not-ready
operator: Exists
tolerationSeconds: 300
- effect: NoExecute
key: node.kubernetes.io/unreachable
operator: Exists
tolerationSeconds: 300
volumes:
- name: task-pv-storage
persistentVolumeClaim:
claimName: task-pv-claim
- name: default-token-tw8wk
secret:
defaultMode: 420
secretName: default-token-tw8wk
status:
conditions:
- lastProbeTime: null
lastTransitionTime: 2019-07-08T06:05:52Z
status: "True"
type: Initialized
- lastProbeTime: null
lastTransitionTime: 2019-07-08T06:05:58Z
status: "True"
type: Ready
- lastProbeTime: null
lastTransitionTime: 2019-07-08T06:05:51Z
status: "True"
type: PodScheduled
containerStatuses:
- containerID: docker://3e9a2ee6b0a13ccee534ec3ffe781adcbff42a7f1851d57e3b374a047a654590
image: nginx:latest
imageID: docker-pullable://nginx@sha256:96fb261b66270b900ea5a2c17a26abbfabe95506e73c3a3c65869a6dbe83223a
lastState: {}
name: task-pv-container
ready: true
restartCount: 0
state:
running:
startedAt: 2019-07-08T06:05:58Z
hostIP: 192.168.65.3
phase: Running
podIP: 10.1.0.103
qosClass: BestEffort
startTime: 2019-07-08T06:05:52Z
spec.container.volumeMounts
spec.container.volumeMounts 其中一个 /usr/share/nginx/html根据 task-pv-storage 挂载到 task-pv-claim 这个共享存储中。这个pvc 是对应哪个共享存储呢?
我们可以查看 kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
task-pv-claim Bound task-pv-volume 1Gi RWO manual 5h
再通过 kubectl get pv
对应到 pv:
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
task-pv-volume 1Gi RWO Retain Bound default/task-pv-claim manual 5h
再查看这个 pv 的详细情况:kubectl describe pv task-pv-volume
Name: task-pv-volume
Labels: type=local
Annotations: kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"PersistentVolume","metadata":{"annotations":{},"labels":{"type":"local"},"name":"task-pv-volume","namespace":""},"spec":{"ac...
pv.kubernetes.io/bound-by-controller=yes
Finalizers: [kubernetes.io/pv-protection]
StorageClass: manual
Status: Bound
Claim: default/task-pv-claim
Reclaim Policy: Retain
Access Modes: RWO
Capacity: 1Gi
Node Affinity: <none>
Message:
Source:
Type: HostPath (bare host directory volume)
Path: /Users/yejianfeng/Documents/workspace/kubernets_example/data
HostPathType:
Events: <none>
看到这个pv对应的是宿主机 HostPath 中的 /Users/yejianfeng/Documents/workspace/kubernets_example/data 这个目录。
所以共享存储的映射关系是 pod -- volume -- pvc -- pv。
其实这里我们之所以说是共享存储,就是说这个存储应该是一个共享网盘,比如 cephFS,而不应该仅仅只是宿主机上的一个目录。宿主机上的目录只是为了调试方便而已。
(1) PV与PVC关系
1.accessMode:访问模型;对象列表:
ReadWriteOnce – the volume can be mounted as read-write by a single node: RWO - ReadWriteOnce一人读写
ReadOnlyMany – the volume can be mounted read-only by many nodes: ROX - ReadOnlyMany 多人只读
ReadWriteMany – the volume can be mounted as read-write by many nodes: RWX - ReadWriteMany多人读写
2.resource:资源限制(比如:定义5GB空间,我们期望对应的存储空间至少5GB。)
3.selector:标签选择器。不加标签,就会在所有PV找最佳匹配。
4.storageClassName:存储类名称:
5.volumeMode:指后端存储卷的模式。可以用于做类型限制,哪种类型的PV可以被当前claim所使用。
6.volumeName:卷名称,指定后端PVC(相当于绑定)
PV和PVC是一一对应关系,当有PV被某个PVC所占用时,会显示banding,其它PVC不能再使用绑定过的PV。
PVC一旦绑定PV,就相当于是一个存储卷,此时PVC可以被多个Pod所使用。(PVC支不支持被多个Pod访问,取决于访问模型accessMode的定义)。
PVC若没有找到合适的PV时,则会处于pending状态。
PV是属于集群级别的,不能定义在名称空间中。
PVC时属于名称空间级别的。
PV的reclaim policy选项:
默认是Retain保留,保留生成的数据。
可以改为recycle回收,删除生成的数据,回收pv
delete,删除,pvc解除绑定后,pv也就自动删除。
容器之间通讯方式\与pod关系的更多相关文章
- K8S 容器之间通讯方式
概述 首先k8s里面容器是存在于pod里面的,所以容器之间通讯,一般分为三种类型: 1. pod内部容器之间 2. pod 与 pod 容器之间 3. pod 访问service服务 pod内部容器之 ...
- 系统之间通讯方式—SOAP(web service)
[web service 简介] 是一种新的web应用程序分支,是自包含.自描述.模块化的应用,可以发布.定位.通过web调用.web service是一个应用组件,它逻辑性的为其他应用程序提供数据与 ...
- Java Servlet与Web容器之间的关系
自从计算机软件开发进入网络时代,就开始涉及到通讯问题.在客户/服务器(也叫C/S应用)时期,每个软件都有自己的客户端和服务器端软件.并且客户端和服务器端之间的通讯协议差别也很大.后来随着互联网的发展, ...
- 侯捷STL学习(五)--allocator和容器之间的实现关系
第十一节 分配器 STL源码学习----内存管理 分配器的好坏影响到容器的性能 operator new()里面调用malloc D:\Program Files (x86)\Microsoft Vi ...
- Web容器、Servlet容器、Spring容器、SpringMVC容器之间的关系
以下内容为个人理解,如有误还请留言指出,不胜感激! Web容器 web容器(web服务器)主要有:Apache.IIS.Tomcat.Jetty.JBoss.webLogic等,而Tomcat.Jet ...
- web容器、sevlet容器、spring容器、springmvc容器之间的关系
原文链接:http://www.cnblogs.com/jieerma666/p/10805966.html https://blog.csdn.net/zhanglf02/article/detai ...
- web容器 web服务器 servlet/jsp容器 之间的区别和关系是什么?
web容器 web服务器 servlet/jsp容器 之间的区别和关系是什么? 这是我在网上找的一些资料:1. Web浏览器除了可以在本地硬盘上打开网页文档外,还可以使用http网络协议从网络上的We ...
- Android--Otto事件总线 -- 组件之间通讯框架使用 --模式解析
前言:Otto事件总线 -- 组件之间通讯框架 对于之前的情况activity之间或者fragment之间等跳转传值一般都是用bundle.intent等,从activityA --- activit ...
- Angular1.x组件通讯方式总结
Angular1开发模式 这里需要将Angular1分为Angular1.5之前和Angular1.5两个不同的阶段来讲,两者虽然同属Angular1,但是在开发模式上还是有较大区别的.在Angula ...
随机推荐
- Python-TypeError: object() takes no parameters
Error: TypeError: object() takes no parameters Where? 使用自定义类的时候,实例类的时候传递参数,提示这个错误 Why? 因为类实例的时候,并不需要 ...
- 【Flutter Widgets大全】电子书开源
[Flutter Widgets大全]是老孟耗费大量精力整理的,总共有330多个组件的详细用法,开源到Github上,希望可以帮助到大家,开源不易,点个赞可不可以. [Flutter Widgets ...
- RHSA-2017:2907-重要: wpa_supplicant 安全更新
[root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) 修复命令: 使用root账号登陆She ...
- 收到DE2+LCM+ D5M套件,拾回DE2,努力,奋进!
今天收到磐转寄的查无此人的DE2二手开发套件,准备用它来做科研验证!今天天是快学的第一天,参加电子设计竞赛会议.开集体会!
- ok6410 3.0.1内核调用V4L接口出错解决方法(转)
在做视频监控项目,以前一直用的是2.6.36的内核,一直很正常,但是这几天换3.0.1内核,启动程序,却出现了错误,如下: ./test_usb_camera XXXXXXXXXXXXXXXXXXXX ...
- IIdea使用CXF开发WebService
写这篇文章主要是用于增强记忆,而我参考的是这位朋友的随笔,链接如下 http://www.xiaomager.com/415.html 服务端开发过程 1.首先创建一个maven项目,如下图 2.添加 ...
- MeteoInfoLab脚本示例:FY-3C全球火点HDF数据
FY-3C全球火点HDF数据包含一个FIRES二维变量,第一维是火点数,第二维是一些属性,其中第3.4列分别是火点的纬度和经度.下面的脚本示例读出所有火点经纬度并绘图.脚本程序: #Add data ...
- 基于python实现顺序存储的栈
""" 栈 sstack.py 栈模型的顺序存储 重点代码 思路总结: 1.列表是顺序存储,但功能多,不符合栈的模型特征 2.利用列表,将其封装,提供接口方法 " ...
- Jmeter请求之接口串联自动化测试(未完)
方案一:添加Cookie管理器,把用户的登录状态存在cookie管理器中,类似于浏览器 存储测试结果: 监听器->保存响应到文件,对结果进行存储 文件名前缀:保存到哪个地方前缀是什么D:\tes ...
- "计算机科学"与"软件工程"有什么区别?哪个专业更适合你?
"计算机科学和软件工程专业有什么不同?" 以及- "如果我想成为软件工程师,我应该选择计算机科学还是软件工程专业?" 在这篇文章中,我会回答这个问题,并分享一些 ...