{"id":369,"date":"2019-01-31T22:36:07","date_gmt":"2019-02-01T03:36:07","guid":{"rendered":"http:\/\/wangxiaohu.com\/blog\/?p=369"},"modified":"2019-02-07T20:54:55","modified_gmt":"2019-02-08T01:54:55","slug":"%e5%9c%a8-k8s-%e4%b8%ad%e5%bc%80%e4%b8%80%e4%b8%aa-shell","status":"publish","type":"post","link":"https:\/\/wangxiaohu.com\/blog\/?p=369","title":{"rendered":"\u5728 k8s \u4e2d\u5f00\u4e00\u4e2a shell"},"content":{"rendered":"\n<p>\u7ecf\u5e38\u9700\u8981\u4e00\u4e2a\u8fdc\u7a0b\u4e34\u65f6\u7684 shell \u505a\u4e9b\u4ec0\u4e48\u4e8b\uff0c\u6bd4\u5982\u5b9e\u9a8c\u4e00\u4e0b\u67d0\u4e2a\u9700\u8981\u8fd0\u884c\u4e00\u665a\u4e0a\u7684\u811a\u672c\uff0c\u7528\u5b8c\u73af\u5883\u5c31\u6254\u4e86\u3002\u5728 AWS \u6216\u8005 Azure \u4e0a\u5f00\u4e00\u4e2a\u65b0\u7684 VM \u603b\u662f\u611f\u89c9\u4e0d\u591f\u5feb\u6377\uff0c\u4e5f\u4e0d\u60f3\u4e13\u95e8\u6d6a\u8d39\u4e00\u4e2a VM \u7684\u8d44\u6e90\u4e3a\u8fd9\u4e2a\u76ee\u7684\u7559\u7740\u3002<\/p>\n\n\n\n<p>\u8fd8\u597d\u6211\u6709\u4e2a Kubernetes \u4e0b\u521b\u5efa pod \u7684\u6743\u9650\uff0c\u8fd9\u4e0b\u5c31\u65b9\u4fbf\u591a\u4e86\u3002<\/p>\n\n\n\n<p>\u9996\u5148\u521b\u5efa\u4e00\u4e2a shell.yaml \u6765\u63cf\u8ff0\u4e00\u4e2a\u53ef\u4ee5\u8fd0\u884c bash shell \u7684 pod\uff08\u5bb9\u5668\u955c\u50cf\u7528\u7684\u662f<a href=\"https:\/\/hub.docker.com\/_\/bash\">\u5b98\u65b9\u7684 bash \u955c\u50cf<\/a>\uff09:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apiVersion: v1\nkind: Pod\nmetadata:\n  name: shell\n  labels:\n    purpose: shell\nspec:\n  containers:\n  - name: shell\n    image: bash\n    command: [\"tail\"]\n    args: [\"-f\", \"\/dev\/null\"]\n  restartPolicy: OnFailure<\/code><\/pre>\n\n\n\n<p>\u7136\u540e\u6267\u884c\u4e0b\u9762\u7684\u547d\u4ee4\u6765\u521b\u5efa\u8fd9\u4e2a pod\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ kubectl apply -f shell.yaml\npod\/shell created<\/code><\/pre>\n\n\n\n<p>\u6210\u529f\u4e4b\u540e\uff0c\u5c31\u53ef\u4ee5\u901a\u8fc7\u4e0b\u9762\u7684\u547d\u4ee4\u83b7\u5f97\u4e00\u4e2a\u8fdc\u7a0b\u7684 shell \u73af\u5883\u4e86\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ kubectl exec -it shell -- bash --login\nshell:\/#<\/code><\/pre>\n\n\n\n<p style=\"font-size:0\">\u8fd9\u4e2a\u65b0\u521b\u5efa\u7684\u73af\u5883\u662f\u57fa\u4e8e alpine linux \u7684\uff0c\u81ea\u7136\u4ec0\u4e48\u5de5\u5177\u90fd\u6ca1\u6709\u81ea\u5e26\u3002\u9700\u8981\u4ec0\u4e48\u5de5\u5177\uff0c\u53ea\u8981\u7528 <code>apk add<\/code> \u547d\u4ee4\u5b89\u88c5\u5c31\u597d\u4e86\u3002\u6211\u56e0\u4e3a\u5de5\u4f5c\u9700\u8981\u4e00\u822c\u90fd\u4f1a\u5b89\u88c5\u4e0b\u9762\u8fd9\u4e9b\u5de5\u5177\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apk add git\napk add nodejs-current\napk add npm\napk add python3<\/code><\/pre>\n\n\n\n<p>\u5982\u679c\u60f3\u4ece\u6216\u8005\u5411\u8fd9\u4e2a pod\/shell \u590d\u5236\u6587\u4ef6\u7684\u8bdd\uff0c\u7528\u4e0b\u9762\u7684\u547d\u4ee4\u5c31\u597d\u4e86\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl cp ... ...<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7ecf\u5e38\u9700\u8981\u4e00\u4e2a\u8fdc\u7a0b\u4e34\u65f6\u7684 shell \u505a\u4e9b\u4ec0\u4e48\u4e8b\uff0c\u6bd4\u5982\u5b9e\u9a8c\u4e00\u4e0b\u67d0\u4e2a\u9700\u8981\u8fd0\u884c\u4e00\u665a\u4e0a\u7684\u811a\u672c\uff0c\u7528\u5b8c\u73af\u5883\u5c31\u6254\u4e86\u3002\u5728 AW &hellip; <a href=\"https:\/\/wangxiaohu.com\/blog\/?p=369\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u5728 k8s \u4e2d\u5f00\u4e00\u4e2a shell<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_jetpack_memberships_contains_paid_content":false},"categories":[16],"tags":[47,46],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","jetpack_likes_enabled":true,"jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pdhZ2A-5X","_links":{"self":[{"href":"https:\/\/wangxiaohu.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/369"}],"collection":[{"href":"https:\/\/wangxiaohu.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wangxiaohu.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wangxiaohu.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/wangxiaohu.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=369"}],"version-history":[{"count":4,"href":"https:\/\/wangxiaohu.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/369\/revisions"}],"predecessor-version":[{"id":374,"href":"https:\/\/wangxiaohu.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/369\/revisions\/374"}],"wp:attachment":[{"href":"https:\/\/wangxiaohu.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wangxiaohu.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=369"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wangxiaohu.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}