目录
一、环境安装
参考
二、HostPath介绍
HostPath就是将Node主机中一个实际目录挂载到Pod中,以供容器使用。
特点:
Pod销毁,但是数据依然可以存在于Node主机上。
三、HostPath使用
示例 yml
vim 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:块设备必须存在
1 创建
kubectl create -f volume-hostpath.yml

2 查看
kubectl get pods -n dev -o wide

本文介绍了如何在Kubernetes环境中安装配置,然后详细讲解了HostPath的概念,它允许将Node主机的目录挂载到Pod的容器中,实现数据持久化。HostPath的特点在于Pod销毁后,数据仍然保留在主机上。文中给出了一个使用HostPath的示例YML配置,包括创建和查看Pod的命令。
2065

被折叠的 条评论
为什么被折叠?



