{"id":18399,"date":"2025-07-09T08:31:19","date_gmt":"2025-07-09T00:31:19","guid":{"rendered":"https:\/\/92it.top\/?p=18399"},"modified":"2025-07-09T08:44:09","modified_gmt":"2025-07-09T00:44:09","slug":"k8s%e6%95%b0%e6%8d%ae%e5%8d%b7-volume-%e4%b9%8b-hostpath-%e4%b8%8e-emptydir","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=18399","title":{"rendered":"k8s\u6570\u636e\u5377 Volume \u4e4b hostPath \u4e0e emptyDir"},"content":{"rendered":"\n<p>\u8f6c\u8f7d\uff1a<a href=\"https:\/\/www.cnblogs.com\/eddyz\/p\/17584633.html\">k8s\u6570\u636e\u5377 Volume \u4e4b hostPath \u4e0e emptyDir<\/a><\/p>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>\u4e00\u3001\u4e3a\u4ec0\u4e48\u9700\u8981 volume\uff08\u6570\u636e\u5377\uff09\uff1f<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u5bb9\u5668\u4e2d\u7684\u6587\u4ef6\u5728\u78c1\u76d8\u4e0a\u662f\u4e34\u65f6\u5b58\u653e\u7684\uff0c\u8fd9\u7ed9\u5bb9\u5668\u4e2d\u8fd0\u884c\u6bd4\u8f83\u91cd\u8981\u7684\u5e94\u7528\u7a0b\u5e8f\u5e26\u6765\u4e00\u4e9b\u95ee\u9898\u3002<\/p>\n\n\n\n<ul>\n<li>\u95ee\u98981\uff1a\u5f53\u5bb9\u5668\u5347\u7ea7\u6216\u8005\u5d29\u6e83\u65f6\uff0ckubelet\u4f1a\u91cd\u5efa\u5bb9\u5668\uff0c\u5bb9\u5668\u5185\u6587\u4ef6\u4f1a\u4e22\u5931<\/li>\n\n\n\n<li>\u95ee\u98982\uff1a\u4e00\u4e2aPod\u4e2d\u8fd0\u884c\u591a\u4e2a\u5bb9\u5668\u9700\u8981\u5171\u4eab\u6587\u4ef6\u3002<\/li>\n<\/ul>\n\n\n\n<p>Kubernetes \u5377\uff08Volume\uff09 \u8fd9\u4e00\u62bd\u8c61\u6982\u5ff5\u80fd\u591f\u89e3\u51b3\u8fd9\u4e24\u4e2a\u95ee\u9898\u3002<\/p>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>\u4e8c\u3001\u5e38\u7528\u6570\u636e\u5377<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<ul>\n<li>\u672c\u5730\uff08emptyDir\uff0chostPath\uff09<\/li>\n\n\n\n<li>\u7f51\u7edc\uff08NFS\uff0cCeph\uff0cGlusterFS\uff09<\/li>\n\n\n\n<li>\u516c\u6709\u4e91\uff08AWS EBS\uff09<\/li>\n\n\n\n<li>K8S\u8d44\u6e90\uff08configmap\uff0csecret\uff09<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"704\" height=\"510\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-100.png\" alt=\"\" class=\"wp-image-18400\" style=\"width:330px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-100.png 704w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-100-300x217.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-100-230x167.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-100-350x254.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-100-480x348.png 480w\" sizes=\"(max-width: 704px) 100vw, 704px\" \/><\/figure><\/div>\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>\u4e09\u3001empryDir<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>emptyDir\u5377\uff1a<\/strong> \u662f\u4e00\u4e2a\u81ea\u52a8\u521b\u5efa\u7684\u3001 Pod \u6240\u5728node\u4e3b\u673a\u4e0a\u7684\u4e34\u65f6\u76ee\u5f55\uff08node\u4e0a\u9884\u8bbe\u5b9a\u597d\u7684\u5b58\u50a8\u4f4d\u7f6e\uff09\uff0c\u4e0ePod\u751f\u547d\u5468\u671f\u7ed1\u5b9a\u5728\u4e00\u8d77\uff0c\u5982\u679cPod\u5220\u9664\u4e86\uff0cemptyDir\u5377\u4e5f\u4f1a\u88ab\u5220\u9664\u3002<br><strong>\u5e94\u7528\u573a\u666f\uff1a<\/strong> Pod\u4e2d\u5bb9\u5668\u4e4b\u95f4\u6570\u636e\u5171\u4eab\uff0c\u5e38\u7528\u4e8e\u540c\u4e00\u4e2apod\u5185\u5bb9\u5668\uff08container\uff09\u4e4b\u95f4\u76f4\u63a5\u7684\u6570\u636e\u4f20\u8f93\u3002<\/p>\n\n\n\n<p><strong>\u4f8b\u5b50<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># \u505a\u4e00\u4e2a\u6d4b\u8bd5yaml\nvi emptydir.yaml<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">apiVersion: v1\nkind: Pod\nmetadata:\n  name: pod1\nspec:\n  containers:\n  - name: write # \u4e1a\u52a1\u5bb9\u5668\uff08\u5199\u6570\u636e\uff09\n    image: centos\n    command: [\"bash\",\"-c\",\"for i in {1..100};do echo $i >> \/data\/hello;sleep 1;done\"]\n    volumeMounts:\n      - name: data\n        mountPath: \/data\n  - name: read # \u8f85\u52a9\u5bb9\u5668\uff08\u8bfb\u6570\u636e\uff09\n    image: centos\n    command: [\"bash\",\"-c\",\"tail -f \/data\/hello\"]\n    volumeMounts:\n      - name: data\n        mountPath: \/data\n  volumes:\n  - name: data\n    emptyDir: {}\n<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">kubectl apply -f emptydir.yaml<\/pre>\n\n\n\n<p>\u8fd9\u4e2a YAML \u6587\u4ef6\u5b9a\u4e49\u4e86\u4e00\u4e2a Kubernetes Pod\uff0c\u901a\u8fc7<strong>emptyDir \u5377<\/strong>\u5b9e\u73b0\u4e24\u4e2a\u5bb9\u5668\u95f4\u7684\u6570\u636e\u5171\u4eab\u3002<\/p>\n\n\n\n<p>\u8fd9\u662f\u4e00\u4e2a\u5178\u578b\u7684<strong>\u4e3b\u5bb9\u5668 + \u8f85\u52a9\u5bb9\u5668<\/strong>\u6a21\u5f0f\uff1a<\/p>\n\n\n\n<ul>\n<li>\u4e3b\u5bb9\u5668\uff08write\uff09\uff1a\u5faa\u73af\u5199\u5165\u6570\u636e\u5230\u5171\u4eab\u76ee\u5f55\u3002<\/li>\n\n\n\n<li>\u8f85\u52a9\u5bb9\u5668\uff08read\uff09\uff1a\u5b9e\u65f6\u8bfb\u53d6\u5e76\u8f93\u51fa\u5171\u4eab\u76ee\u5f55\u4e2d\u7684\u6570\u636e\u3002<\/li>\n\n\n\n<li>emptyDir \u5377\uff1a\u4f5c\u4e3a\u4e34\u65f6\u5b58\u50a8\uff0c\u8fde\u63a5\u4e24\u4e2a\u5bb9\u5668\u7684\u6570\u636e\u901a\u8def\u3002<\/li>\n<\/ul>\n\n\n\n<p> \u3000<\/p>\n\n\n\n<p>\u4e3b\u5bb9\u5668\uff08\u5199\u5165\u6570\u636e\uff09<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">- name: write\n  image: centos\n  command: [\"bash\",\"-c\",\"for i in {1..100};do echo $i >> \/data\/hello;sleep 1;done\"]\n  volumeMounts:\n    - name: data\n      mountPath: \/data<\/pre>\n\n\n\n<ul>\n<li>\u6bcf\u79d2\u5411<code>\/data\/hello<\/code>\u6587\u4ef6\u8ffd\u52a0\u4e00\u4e2a\u6570\u5b57\uff08\u4ece 1 \u5230 100\uff09\u3002<\/li>\n\n\n\n<li><code>>><\/code>\uff1a\u8ffd\u52a0\u5199\u5165\uff0c\u907f\u514d\u8986\u76d6\u539f\u6709\u5185\u5bb9\u3002<\/li>\n\n\n\n<li><code>\/data<\/code>\u76ee\u5f55\u6620\u5c04\u5230 emptyDir \u5377\uff08<code>data<\/code>\uff09\uff0c\u786e\u4fdd\u6570\u636e\u53ef\u88ab\u53e6\u4e00\u4e2a\u5bb9\u5668\u8bbf\u95ee\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p>\u8f85\u52a9\u5bb9\u5668\uff08\u8bfb\u53d6\u6570\u636e\uff09<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">- name: read\n  image: centos\n  command: [\"bash\",\"-c\",\"tail -f \/data\/hello\"]\n  volumeMounts:\n    - name: data\n      mountPath: \/data<\/pre>\n\n\n\n<ul>\n<li>\u4f7f\u7528<code>tail -f<\/code>\u5b9e\u65f6\u76d1\u63a7\u5e76\u8f93\u51fa<code>\/data\/hello<\/code>\u6587\u4ef6\u7684\u66f4\u65b0\u5185\u5bb9\u3002<\/li>\n\n\n\n<li><code>tail -f<\/code>\uff1a\u6301\u7eed\u8ddf\u8e2a\u6587\u4ef6\u53d8\u5316\uff0c\u65b0\u5185\u5bb9\u4f1a\u7acb\u5373\u663e\u793a\u3002<\/li>\n\n\n\n<li>\u4e0e\u4e3b\u5bb9\u5668\u6302\u8f7d\u540c\u4e00 emptyDir \u5377\uff0c\u786e\u4fdd\u80fd\u8bfb\u53d6\u5230\u5199\u5165\u7684\u6570\u636e\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p>emptyDir \u5377\uff08\u6570\u636e\u5171\u4eab\u6838\u5fc3\uff09<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">volumes:\n  - name: data\n    emptyDir: {}<\/pre>\n\n\n\n<ul>\n<li>\u5728 Pod \u5185\u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u76ee\u5f55\uff0c\u4f9b\u6240\u6709\u5bb9\u5668\u5171\u4eab\u3002<\/li>\n\n\n\n<li>\u751f\u547d\u5468\u671f\u4e0e Pod \u7ed1\u5b9a\uff1aPod \u521b\u5efa\u65f6\u751f\u6210\uff0c\u5220\u9664\u65f6\u9500\u6bc1\u3002<\/li>\n\n\n\n<li>\u5bb9\u5668\u95f4\u53ef\u89c1\uff1a\u6240\u6709\u6302\u8f7d\u8be5\u5377\u7684\u5bb9\u5668\u53ef\u8bfb\u5199\u540c\u4e00\u76ee\u5f55\u3002<\/li>\n\n\n\n<li>\u9ed8\u8ba4\u5b58\u50a8\u5728\u8282\u70b9\u78c1\u76d8\uff1a\u4e5f\u53ef\u914d\u7f6e\u4e3a\u5185\u5b58\u5b58\u50a8\uff08<code>medium: Memory<\/code>\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p>\u5de5\u4f5c\u6d41\u7a0b<\/p>\n\n\n\n<ol>\n<li>Pod \u542f\u52a8\uff1aKubernetes \u521b\u5efa Pod\uff0c\u540c\u65f6\u521d\u59cb\u5316 emptyDir \u5377\uff08\u521d\u59cb\u4e3a\u7a7a\uff09\u3002<\/li>\n\n\n\n<li>\u6570\u636e\u5199\u5165\uff1a\n<ul>\n<li><code>write<\/code>\u5bb9\u5668\u542f\u52a8\uff0c\u6267\u884c\u5faa\u73af\u811a\u672c\u3002<\/li>\n\n\n\n<li>\u6bcf\u79d2\u5411<code>\/data\/hello<\/code>\u5199\u5165\u4e00\u4e2a\u6570\u5b57\uff08\u5982<code>1<\/code>\u3001<code>2<\/code>\u3001<code>3<\/code>&#8230;\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>\u6570\u636e\u8bfb\u53d6\uff1a\n<ul>\n<li><code>read<\/code>\u5bb9\u5668\u542f\u52a8\uff0c\u6267\u884c<code>tail -f \/data\/hello<\/code>\u3002<\/li>\n\n\n\n<li>\u5b9e\u65f6\u76d1\u63a7\u6587\u4ef6\u53d8\u5316\uff0c\u65b0\u5199\u5165\u7684\u6570\u5b57\u4f1a\u7acb\u5373\u663e\u793a\u5728<code>read<\/code>\u5bb9\u5668\u7684\u65e5\u5fd7\u4e2d\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>\u7ed3\u679c\u9a8c\u8bc1\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">kubectl logs pod1 read  # \u67e5\u770bread\u5bb9\u5668\u7684\u65e5\u5fd7\uff0c\u4f1a\u770b\u5230\u9012\u589e\u7684\u6570\u5b57\n<\/pre>\n\n\n\n<p>\u6267\u884c\u540e\uff0c\u53ef\u4ee5\u770b\u5230\u4e24\u4e2a\u6587\u4ef6data\u662f\u5171\u4eab\u7684\uff0c\u6d4b\u8bd5\u53ef\u4ee5\u770b\u5230\u4e24\u4e2a\u6587\u4ef6\u662f\u5171\u4eab\u7684\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"421\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-101-1024x421.png\" alt=\"\" class=\"wp-image-18401\" style=\"width:534px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-101-1024x421.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-101-300x123.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-101-768x316.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-101-830x341.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-101-230x95.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-101-350x144.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-101-480x197.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-101.png 1036w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>empryDir\u5728k8s\u4e2d\u7684\u5b58\u50a8\u4f4d\u7f6e<\/p>\n\n\n\n<p>\u4e00\u822c\u5728 <code>\/var\/lib\/kubelet\/pods\/{pod-id}\/volumes\/kubernetes.io~empty-dir<\/code> \u4e0b\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"267\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-102-1024x267.png\" alt=\"\" class=\"wp-image-18402\" style=\"width:542px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-102-1024x267.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-102-300x78.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-102-768x200.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-102-830x216.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-102-230x60.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-102-350x91.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-102-480x125.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-102.png 1412w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>\u56db\u3001hostPath<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>hostPath\u5377\uff1a<\/strong> \u6302\u8f7dNode\u6587\u4ef6\u7cfb\u7edf\uff08Pod\u6240\u5728\u8282\u70b9\uff09\u4e0a\u6587\u4ef6\u6216\u8005\u76ee\u5f55\u5230Pod\u4e2d\u7684\u5bb9\u5668\u3002<br><strong>\u5e94\u7528\u573a\u666f\uff1a<\/strong> Pod\u4e2d\u5bb9\u5668\u9700\u8981\u8bbf\u95ee\u5bbf\u4e3b\u673a\u6587\u4ef6\u3002\u4f46\u4e0d\u9002\u5408\u505a\u6301\u4e45\u5316\u3002<\/p>\n\n\n\n<p>\u793a\u4f8b<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">vi hostPath.yaml<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">apiVersion: v1\nkind: Pod\nmetadata:\n  name: pod2\nspec:\n  containers:\n  - name: write # \u4e1a\u52a1\u5bb9\u5668\uff08\u5199\u6570\u636e\uff09\n    image: centos\n    command: [\"bash\",\"-c\",\"for i in {1..1000};do echo $i >> \/data\/hello;sleep 1;done\"]\n    volumeMounts:\n      - name: data\n        mountPath: \/ttt\n  volumes:\n  - name: data\n    hostPath:\n      path: \/tmp\n      type: Directory # \u6587\u4ef6\u7c7b\u578b\uff1a\u5b9a\u4e49node\u4e3b\u673a\u4e0a\u7684 \/tmp \u662f\u6587\u4ef6\u5939\u8fd8\u662f\u6587\u4ef6\u3002\n\n<\/pre>\n\n\n\n<p>\u6d4b\u8bd5\uff0c\u5728 pod \u7684 <code>\/ttt<\/code> \u76ee\u5f55\u4e0b\u5199\u5165\u4e00\u4e2a123\u6587\u4ef6\u540e\uff0c\u67e5\u770b\u6b64pod\u6240\u5904\u8282\u70b9<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"798\" height=\"242\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-103.png\" alt=\"\" class=\"wp-image-18403\" style=\"width:438px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-103.png 798w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-103-300x91.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-103-768x233.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-103-230x70.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-103-350x106.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-103-480x146.png 480w\" sizes=\"(max-width: 798px) 100vw, 798px\" \/><\/figure><\/div>\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># \u67e5\u770b pod \u6240\u5728\u7684 node \nkubectl get pods -o wide<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"259\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-104-1024x259.png\" alt=\"\" class=\"wp-image-18404\" style=\"width:604px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-104-1024x259.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-104-300x76.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-104-768x194.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-104-1536x389.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-104-830x210.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-104-230x58.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-104-350x89.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-104-480x121.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-104.png 1604w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u8fdb\u5165node1\u8282\u70b9tmp\u4e0b\u67e5\u770b<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"224\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-105-1024x224.png\" alt=\"\" class=\"wp-image-18405\" style=\"width:620px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-105-1024x224.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-105-300x66.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-105-768x168.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-105-830x181.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-105-230x50.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-105-350x76.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-105-480x105.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2025\/07\/image-105.png 1034w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>\u4e94\u3001emptyDir \u4e0e hostPath \u7684\u533a\u522b<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>\u76f8\u540c\u70b9<\/strong><\/p>\n\n\n\n<ul>\n<li>emptyDir \u548c hostPath \u7c7b\u578b\u90fd\u53ef\u7528\u4e8e container \u4e4b\u95f4\u6570\u636e\u5171\u4eab\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>\u533a\u522b<\/strong><\/p>\n\n\n\n<ul>\n<li>emptyDir \u662f pod \u7ea7\u522b\u7684\u3002pod \u9500\u6bc1\u540e\uff0c emptyDir \u4e5f\u4f1a\u9500\u6bc1\u3002<\/li>\n\n\n\n<li>emptyDir \u88ab\u521d\u59cb\u5316\u540e\u91cc\u9762\u662f\u7a7a\u7684\u3002\u6240\u6709\u5728\u540c\u4e00\u4e2a pod \u4e2d\u7684 container \u90fd\u53ef\u4ee5\u901a\u8fc7\u6302\u8f7demptyDir\u540e\u5bf9\u5176\u8fdb\u884c\u8bfb\u5199\u64cd\u4f5c\u3002<\/li>\n\n\n\n<li>emptyDir \u4e3b\u8981\u7528\u4e8e\u540c\u4e00\u4e2a pod \u4e2d\u7684 container \u4e4b\u95f4\u5171\u4eab\u6570\u636e\u3002\uff08\u5982\uff1alog \u65e5\u5fd7\u76ee\u5f55\uff09<\/li>\n\n\n\n<li>emptyDir \u4f7f\u7528 emptyDir \u8fd9\u79cd volume \u65f6\uff0c\u4e00\u4e2apod\u4e2d\u4e00\u822c\u4f1a\u67092\u4e2a\u4ee5\u4e0a\u7684 container\u3002<\/li>\n\n\n\n<li>hostPath \u662f node \u7ea7\u522b\u7684\uff0cnode \u662f\u6301\u4e45\u5316\u7684\u3002\u4e00\u4e2a node \u53ef\u4ee5\u521b\u5efa N \u4e2a pod \u3002<\/li>\n<\/ul>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>emptyDir<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">apiVersion: v1\nkind: Pod\nmetadata:\n  name: my-pod\nspec:\n  containers:\n  - name: my-app\n    image: my-app-image\n    volumeMounts:\n    - mountPath: \/cache\n      name: cache-volume\n  - name: sidecar\n    image: busybox\n    volumeMounts:\n    - mountPath: \/cache\n      name: cache-volume\n  volumes:\n  - name: cache-volume\n    emptyDir: {}<\/pre>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>hostPath<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">apiVersion: v1\nkind: Pod\nmetadata:\n  name: my-pod\nspec:\n  containers:\n  - name: my-app\n    image: my-app-image\n    volumeMounts:\n      - name: test-volume\n        mountPath: \/test-pd\n  volumes:\n  - name: test-volume \n    hostPath:\n      path: \/data      # directory on host\n      type: Directory  # optional \n\n# type:\n# Other values for type are 'DirectoryOrCreate', 'File', 'FileOrCreate'. \n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u8f6c\u8f7d\uff1ak8s\u6570\u636e\u5377 Volume \u4e4b hostPath \u4e0e emptyDir \u3000 \u4e00\u3001\u4e3a\u4ec0\u4e48\u9700\u8981 volume [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/18399"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=18399"}],"version-history":[{"count":3,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/18399\/revisions"}],"predecessor-version":[{"id":18408,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/18399\/revisions\/18408"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=18399"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=18399"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=18399"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}