使用宿主机目录作为存储卷去挂载到pod内部
[root@hdss7-200 volume]# vim /data/k8s-yaml/base_resource/volume/hostpath.yaml
apiVersion: v1
kind: Pod
metadata:
name: pod-hostpath
namespace: app
labels:
tier: volume
role: hostpath
spec:
containers:
- name: main-container
image: harbor.od.com/public/busybox:v1.31.1
volumeMounts:
- name: web-root
mountPath: /data/web/html
command:
- httpd
args:
- -f
- -h
- "/data/web/html"
volumes:
- name: web-root
hostPath:
path: /tmp/pod-hostpath/html
type: DirectoryOrCreate
nodeSelector:
kubernetes.io/hostname: hdss7-21.host.com
[root@hdss7-21 ~]# kubectl apply -f http://k8s-yaml.od.com/base_resource/volume/hostpath.yaml
[root@hdss7-21 ~]# kubectl get pod pod-hostpath -o wide -n app
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod-hostpath 1/1 Running 0 19s 172.7.21.11 hdss7-21.host.com <none> <none>
[root@hdss7-21 ~]# echo hello world > /tmp/pod-hostpath/html/index.html
[root@hdss7-21 ~]# curl -s 172.7.21.11
hello world