Kubernetes 数据存储 HostPath
Kubernetes 评论 1 大约 1388 字概念
HostPath
就是将Node
主机中一个实际目录挂载到Pod
中,以供容器使用。
特点
Pod
销毁,但是数据依然可以存在于Node
主机上。
示例 yml
volume-hostpath.yml
apiVersion: v1
kind: Pod
metadata:
name: volume-hostpath
namespace: dev
spec:
containers:
- name: nginx
image: nginx:1.17.1
ports:
- containerPort: 80
volumeMounts:
- name: logs-volume
mountPath: /var/log/nginx
- name: busybox
image: busybox:1.30
command: ["/bin/sh","-c","tail -f /logs/access.log"]
volumeMounts:
- name: logs-volume
mountPath: /logs
volumes:
- name: logs-volume
hostPath:
path: /root/logs
type: DirectoryOrCreate # 目录存在就使用,不存在就先创建后使用
hostPath
的type
说明:
DirectoryOrCreate
:目录存在就使用,不存在就先创建后使用Directory
:目录必须存在FileOrCreate
:文件存在就使用,不存在就先创建后使用File
:文件必须存在Socket
:Unix
套接字必须存在CharDevice
:字符设备必须存在BlockDevice
:块设备必须存在
查看 Pod
kubectl get pods -n dev -o wide
输出:
[root@localhost ~]# kubectl get pods -n dev -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
volume-hostpath 2/2 Running 0 14s 10.42.0.45 localhost.localdomain <none> <none>
查看日志
另一个终端中访问Nginx
curl 10.42.0.45
查看日志:(宿主机/root/logs
目录)
tail -f /root/logs/access.log
输出:
[root@localhost ~]# tail -f /root/logs/access.log
10.42.0.1 - - [04/Feb/2022:01:30:28 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.29.0" "-"
阅读 1206 · 发布于 2022-03-19
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb扫描下方二维码关注公众号和小程序↓↓↓
昵称:
-
fHLvlxbf 1楼
e
Chrome | Windows 10 2023-07-24
随便看看
换一批
-
OpenLens 6.3.0 无法查案日志和进入 Pod Shell 解决方法阅读 2310
-
Linux 配置 top 命令显示 swap阅读 5792
-
PostgreSQL 批量更新阅读 323
-
Windows WSL 下 Docker 启动报 waiting for init preliminary setup caused: EOF: unknown 错误阅读 3979
-
Spring Boot Thymeleaf URL 链接阅读 285
-
PostgreSQL PSQLException: ERROR: syntax error at or near "user"阅读 321
-
设计模式之装饰者模式阅读 2142
-
Java jps 无法显示进程 id阅读 634
-
Windows 系统保留端口阅读 1606
-
Android 生成 shape 图形阅读 2437