当前位置:  首页>> 技术小册>> Kubernets合辑7-存储

使用宿主机目录作为存储卷去挂载到pod内部

  1. [root@hdss7-200 volume]# vim /data/k8s-yaml/base_resource/volume/hostpath.yaml
  2. apiVersion: v1
  3. kind: Pod
  4. metadata:
  5. name: pod-hostpath
  6. namespace: app
  7. labels:
  8. tier: volume
  9. role: hostpath
  10. spec:
  11. containers:
  12. - name: main-container
  13. image: harbor.od.com/public/busybox:v1.31.1
  14. volumeMounts:
  15. - name: web-root
  16. mountPath: /data/web/html
  17. command:
  18. - httpd
  19. args:
  20. - -f
  21. - -h
  22. - "/data/web/html"
  23. volumes:
  24. - name: web-root
  25. hostPath:
  26. path: /tmp/pod-hostpath/html
  27. type: DirectoryOrCreate
  28. nodeSelector:
  29. kubernetes.io/hostname: hdss7-21.host.com
  1. [root@hdss7-21 ~]# kubectl apply -f http://k8s-yaml.od.com/base_resource/volume/hostpath.yaml
  2. [root@hdss7-21 ~]# kubectl get pod pod-hostpath -o wide -n app
  3. NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
  4. pod-hostpath 1/1 Running 0 19s 172.7.21.11 hdss7-21.host.com <none> <none>
  5. [root@hdss7-21 ~]# echo hello world > /tmp/pod-hostpath/html/index.html
  6. [root@hdss7-21 ~]# curl -s 172.7.21.11
  7. hello world

该分类下的相关小册推荐: