kubernetes - Kubernetes emptyDir 卷中不同容器中同一文件的不完整尾部输出
问题描述
为了测试 emptyDir Volume 中的文件是否在容器之间同步,我使用tail观察了两个容器中的同一个文件,我偶然发现了以下行为:
吊舱定义:
apiVersion: v1
kind: Pod
metadata:
name: fortune
spec:
containers:
- image: luksa/fortune
name: html-generator
volumeMounts:
- name: html
mountPath: /var/htdocs
- image: nginx:alpine
name: web-server
volumeMounts:
- name: html
mountPath: /usr/share/nginx/html
readOnly: true
ports:
- containerPort: 80
protocol: TCP
volumes:
- name: html
emptyDir: {}
示例取自Marko Luksa的Kubernetes in Action一书。luksa/fortune
图像只是将财富文本写入容器/var/htdocs/index.html
内的文件。html-generator
每 10 秒写入一个新文件,其中的内容是fortune
.
在两个容器中拖尾相同的文件有时会输出容器的不完整响应web-server
。
部分html-generator
容器输出:
kubectl exec -c html-generator -it fortune -- tail -f /var/htdocs/index.html
The very ink with which all history is written is merely fluid prejudice.
-- Mark Twain
部分web-server
容器输出
kubectl exec -c web-server -it fortune -- tail -f /usr/share/nginx/html/index.html
h all history is written is merely fluid prejudice.
-- Mark Twain
问题:这是由
- 尾巴
- 节点磁盘IO速度慢
- Kubernetes 卷同步逻辑
- 别的东西?
PS.:我还注意到,在写入 index.html 时卷曲 Web 服务 pod 端口会导致 nginx 返回一个空的响应正文。
解决方案
容器输出不完整的问题是由nginx alpine
在 pod 定义中使用引起的。当您将图像从 更改为 时nginx:alpine
,nginx
由于这些图像中使用了不同的尾部二进制文件,问题就会消失。
Kubernetes 卷同步似乎不太可能导致问题 - 如emptyDir
文档中所写
默认情况下,
emptyDir
卷存储在支持节点的任何介质上——可能是磁盘、SSD 或网络存储,具体取决于您的环境。
emptyDir 创建的分区是短暂的,应用程序不能期望该分区有任何性能 SLA(例如磁盘 IOPS),因此“2. 节点磁盘的 IO 速度慢”也可能导致此类问题,但基于再现和更改图像(看起来解决问题)可能会被排除在外。
推荐阅读
- angular - Angular 5.2:使用服务跨路由的数据持久性
- java - 使用巴西夏令时 (BRST) 时的日期格式错误
- java - 使用 Log4j 进行日志轮换的问题
- r - 如何在 R 中更有效地计算积分?
- javascript - AddEventlistener 函数调用的 JavaScript 问题
- css - 如何在调整窗口大小时将内容区域保持在 SVG 形状内而不移动到形状外
- javascript - 如何更新 Mongoose 模型阵列?
- python - 如果作者没有某些角色,如何制作一个删除带有附件的消息的不和谐机器人
- sql - 实体关系图-酒店
- powershell-3.0 - 下面的脚本运行良好,直到我决定将输出发送到电子邮件