{"id":330,"date":"2025-01-16T13:35:42","date_gmt":"2025-01-16T05:35:42","guid":{"rendered":"https:\/\/zhaoyanqi.cn\/?p=330"},"modified":"2025-01-16T13:35:43","modified_gmt":"2025-01-16T05:35:43","slug":"%e7%94%a8busybox%e6%b5%8b%e8%af%95%e5%92%8c%e8%b0%83%e8%af%95k8s%e9%9b%86%e7%be%a4%e4%b8%ad%e7%9a%84%e7%bd%91%e7%bb%9c%ef%bc%8c%e5%ad%98%e5%82%a8%ef%bc%8c%e8%bf%90%e8%a1%8c%e6%97%b6","status":"publish","type":"post","link":"https:\/\/zhaoyanqi.cn\/?p=330","title":{"rendered":"\u7528busybox\u6d4b\u8bd5\u548c\u8c03\u8bd5k8s\u96c6\u7fa4\u4e2d\u7684\u7f51\u7edc\uff0c\u5b58\u50a8\uff0c\u8fd0\u884c\u65f6"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"93539a5f\">1. <strong>\u8c03\u8bd5 Kubernetes \u96c6\u7fa4<\/strong><\/h2>\n\n\n\n<p id=\"ua042ced8\"><code>busybox<\/code> \u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684\u5de5\u5177\u7bb1\uff0c\u975e\u5e38\u9002\u5408\u7528\u4e8e\u6d4b\u8bd5\u548c\u8c03\u8bd5 Kubernetes \u96c6\u7fa4\u4e2d\u7684\u7f51\u7edc\u3001\u5b58\u50a8\u548c\u8fd0\u884c\u65f6\u884c\u4e3a\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"00eed425\">1.1 \u6d4b\u8bd5\u7f51\u7edc\u8fde\u901a\u6027<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6d4b\u8bd5 Pod \u4e0e\u5176\u4ed6\u670d\u52a1\u7684\u7f51\u7edc\u8fde\u63a5\uff1a<\/li>\n<\/ul>\n\n\n\n<pre id=\"A7iFt\" class=\"wp-block-code\"><code>kubectl exec -it busybox -- ping &lt;service-name&gt;<\/code><\/pre>\n\n\n\n<p id=\"u79041a00\">\u793a\u4f8b\uff1a<\/p>\n\n\n\n<pre id=\"mQPvb\" class=\"wp-block-code\"><code>kubectl exec -it busybox -- ping google.com<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6d4b\u8bd5 Pod \u95f4\u7f51\u7edc\u901a\u4fe1\uff1a<\/li>\n<\/ul>\n\n\n\n<pre id=\"bZrqg\" class=\"wp-block-code\"><code>kubectl exec -it busybox -- ping &lt;pod-ip&gt;<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" id=\"FQhws\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"8b730bdc\">1.2 \u6d4b\u8bd5 DNS \u89e3\u6790<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u786e\u8ba4 Kubernetes \u96c6\u7fa4\u7684 DNS \u670d\u52a1\u662f\u5426\u6b63\u5e38\u5de5\u4f5c\uff1a<\/li>\n<\/ul>\n\n\n\n<pre id=\"Qhmbg\" class=\"wp-block-code\"><code>kubectl exec -it busybox -- nslookup kubernetes.default<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u67e5\u770b DNS \u914d\u7f6e\uff1a<\/li>\n<\/ul>\n\n\n\n<pre id=\"wh0Gt\" class=\"wp-block-code\"><code>kubectl exec -it busybox -- cat \/etc\/resolv.conf<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" id=\"rYJi1\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"af5b377a\">1.3 \u6d4b\u8bd5 HTTP \u670d\u52a1<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f7f\u7528 <code>wget<\/code> \u6d4b\u8bd5\u670d\u52a1\uff1a<\/li>\n<\/ul>\n\n\n\n<pre id=\"vcf3f\" class=\"wp-block-code\"><code>kubectl exec -it busybox -- wget -qO- http:\/\/&lt;service-name&gt;<\/code><\/pre>\n\n\n\n<p id=\"u6fabc693\">\u793a\u4f8b\uff1a<\/p>\n\n\n\n<pre id=\"SerxC\" class=\"wp-block-code\"><code>kubectl exec -it busybox -- wget -qO- http:\/\/my-app-service<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" id=\"SFVrE\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"c5da02f0\">2. <strong>\u6d4b\u8bd5\u5b58\u50a8\u6302\u8f7d<\/strong><\/h2>\n\n\n\n<p id=\"u54dd1ca8\">\u5728 <code>busybox<\/code> \u4e2d\uff0c\u53ef\u4ee5\u9a8c\u8bc1\u5b58\u50a8\u5377\u662f\u5426\u6b63\u786e\u6302\u8f7d\u5230 Pod\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"1b11975e\">YAML \u6587\u4ef6\u793a\u4f8b<\/h3>\n\n\n\n<pre id=\"vfGLa\" class=\"wp-block-code\"><code>apiVersion: v1\nkind: Pod\nmetadata:\n  name: busybox\nspec:\n  containers:\n  - name: busybox\n    image: busybox\n    command: &#91;\"sh\", \"-c\", \"while true; do sleep 3600; done\"]\n    volumeMounts:\n    - name: test-volume\n      mountPath: \/mnt\n  volumes:\n  - name: test-volume\n    emptyDir: {}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"23459097\">\u68c0\u67e5\u6302\u8f7d<\/h3>\n\n\n\n<p id=\"u3977e579\">\u9a8c\u8bc1\u5b58\u50a8\u662f\u5426\u53ef\u7528\uff1a<\/p>\n\n\n\n<pre id=\"cOtqo\" class=\"wp-block-code\"><code>kubectl exec -it busybox -- ls \/mnt<\/code><\/pre>\n\n\n\n<p id=\"u76edfd73\">\u5199\u5165\u548c\u8bfb\u53d6\u6587\u4ef6\uff1a<\/p>\n\n\n\n<pre id=\"IzpJ6\" class=\"wp-block-code\"><code>kubectl exec -it busybox -- sh -c \"echo 'Hello, Kubernetes' &gt; \/mnt\/test-file\"\nkubectl exec -it busybox -- cat \/mnt\/test-file<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" id=\"DWptI\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"5bf4b010\">3. <strong>\u8fd0\u884c\u8f7b\u91cf\u7ea7\u4efb\u52a1<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7b80\u5355\u8ba1\u7b97\u4efb\u52a1<\/strong>\uff1a \u4f7f\u7528 <code>busybox<\/code> \u8fd0\u884c\u7b80\u5355\u7684\u8ba1\u7b97\u4efb\u52a1\u6216\u547d\u4ee4\uff1a<\/li>\n<\/ul>\n\n\n\n<pre id=\"RDPdK\" class=\"wp-block-code\"><code>kubectl exec -it busybox -- expr 5 + 5<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5b9a\u671f\u4efb\u52a1<\/strong>\uff1a \u4f7f\u7528 <code>busybox<\/code> \u521b\u5efa\u8f7b\u91cf\u7ea7\u7684\u5b9a\u671f\u4efb\u52a1\uff0c\u4f8b\u5982\u6e05\u7406\u65e5\u5fd7\u6587\u4ef6\u6216\u5b9a\u671f\u68c0\u67e5\u72b6\u6001\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" id=\"QXwKJ\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"6d4bc4e6\">4. <strong>\u6a21\u62df\u5bb9\u5668\u8fd0\u884c<\/strong><\/h2>\n\n\n\n<p id=\"u3629ab79\">\u5982\u679c\u4f60\u9700\u8981\u6a21\u62df\u4e00\u4e2a\u7b80\u5355\u7684\u5bb9\u5668\u8fd0\u884c\u73af\u5883\uff0c<code>busybox<\/code> \u662f\u4e00\u4e2a\u5f88\u597d\u7684\u9009\u62e9\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"1a63ac23\">\u793a\u4f8b<\/h3>\n\n\n\n<p id=\"u9b458a44\">\u6a21\u62df\u4e00\u4e2a\u957f\u671f\u8fd0\u884c\u7684\u5bb9\u5668\uff1a<\/p>\n\n\n\n<pre id=\"yfUcT\" class=\"wp-block-code\"><code>apiVersion: v1\nkind: Pod\nmetadata:\n  name: busybox\nspec:\n  containers:\n  - name: busybox\n    image: busybox\n    command: &#91;\"sh\", \"-c\", \"while true; do echo Hello Kubernetes; sleep 10; done\"]<\/code><\/pre>\n\n\n\n<p id=\"u117c2bed\">\u67e5\u770b\u65e5\u5fd7\uff1a<\/p>\n\n\n\n<pre id=\"fN7Zb\" class=\"wp-block-code\"><code>kubectl logs busybox<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" id=\"lKTmi\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"590c6af4\">5. <strong>\u6570\u636e\u5904\u7406\u548c\u5c0f\u578b\u811a\u672c\u8fd0\u884c<\/strong><\/h2>\n\n\n\n<p id=\"u62361c7f\"><code>busybox<\/code> \u5305\u542b\u57fa\u672c\u7684\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u4e8e\u7b80\u5355\u7684\u6570\u636e\u5904\u7406\u548c\u811a\u672c\u6267\u884c\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"1a63ac23-1\">\u793a\u4f8b<\/h3>\n\n\n\n<p id=\"u315e9b7f\">\u90e8\u7f72\u4e00\u4e2a\u5305\u542b\u7b80\u5355\u811a\u672c\u7684 <code>busybox<\/code>\uff1a<\/p>\n\n\n\n<pre id=\"GFikL\" class=\"wp-block-code\"><code>apiVersion: v1\nkind: Pod\nmetadata:\n  name: busybox\nspec:\n  containers:\n  - name: busybox\n    image: busybox\n    command: &#91;\"sh\", \"-c\", \"echo 'Starting task'; sleep 10; echo 'Task complete'\"]<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" id=\"NdHxy\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"e6bd5054\">6. <strong>\u9a8c\u8bc1 Kubernetes \u8d44\u6e90\u914d\u7f6e<\/strong><\/h2>\n\n\n\n<p id=\"u9c8d0893\"><code>busybox<\/code> \u53ef\u4ee5\u4f5c\u4e3a\u4e00\u4e2a\u901a\u7528\u6d4b\u8bd5\u5de5\u5177\uff0c\u9a8c\u8bc1 Kubernetes \u4e2d\u5404\u79cd\u8d44\u6e90\uff08\u5982 ConfigMap\u3001Secrets\uff09\u662f\u5426\u6b63\u786e\u914d\u7f6e\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"63ce3ef5\">\u6d4b\u8bd5 ConfigMap<\/h3>\n\n\n\n<pre id=\"d5Lhk\" class=\"wp-block-code\"><code>apiVersion: v1\nkind: ConfigMap\nmetadata:\n  name: example-config\ndata:\n  key1: value1<\/code><\/pre>\n\n\n\n<p id=\"u3e619418\">\u90e8\u7f72 <code>busybox<\/code> \u9a8c\u8bc1 ConfigMap\uff1a<\/p>\n\n\n\n<pre id=\"VtqwD\" class=\"wp-block-code\"><code>apiVersion: v1\nkind: Pod\nmetadata:\n  name: busybox\nspec:\n  containers:\n  - name: busybox\n    image: busybox\n    command: &#91;\"sh\", \"-c\", \"while true; do sleep 3600; done\"]\n    env:\n    - name: CONFIG_KEY\n      valueFrom:\n        configMapKeyRef:\n          name: \n          key: key1<\/code><\/pre>\n\n\n\n<p id=\"ueee5df49\">\u9a8c\u8bc1 ConfigMap \u503c\uff1a<\/p>\n\n\n\n<pre id=\"l5Ur5\" class=\"wp-block-code\"><code>kubectl exec -it busybox -- printenv CONFIG_KEY<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1. \u8c03\u8bd5 Kubernetes \u96c6\u7fa4 busybox \u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684\u5de5\u5177\u7bb1\uff0c\u975e\u5e38\u9002\u5408\u7528\u4e8e\u6d4b\u8bd5\u548c\u8c03\u8bd5 Kube [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-330","post","type-post","status-publish","format-standard","hentry","category-k8s"],"_links":{"self":[{"href":"https:\/\/zhaoyanqi.cn\/index.php?rest_route=\/wp\/v2\/posts\/330","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhaoyanqi.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhaoyanqi.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhaoyanqi.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhaoyanqi.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=330"}],"version-history":[{"count":1,"href":"https:\/\/zhaoyanqi.cn\/index.php?rest_route=\/wp\/v2\/posts\/330\/revisions"}],"predecessor-version":[{"id":331,"href":"https:\/\/zhaoyanqi.cn\/index.php?rest_route=\/wp\/v2\/posts\/330\/revisions\/331"}],"wp:attachment":[{"href":"https:\/\/zhaoyanqi.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=330"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhaoyanqi.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=330"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhaoyanqi.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=330"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}