{"id":655,"date":"2025-11-20T17:02:34","date_gmt":"2025-11-20T09:02:34","guid":{"rendered":"https:\/\/189505.xyz\/?p=655"},"modified":"2025-11-21T16:49:44","modified_gmt":"2025-11-21T08:49:44","slug":"k8s%e9%9b%86%e7%be%a4","status":"publish","type":"post","link":"https:\/\/189505.xyz\/?p=655","title":{"rendered":"k8s\u96c6\u7fa4"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_40 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" area-label=\"ez-toc-toggle-icon-1\"><label for=\"item-69e01ac2e984f\" aria-label=\"Table of Content\"><span style=\"display: flex;align-items: center;width: 35px;height: 30px;justify-content: center;direction:ltr;\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/label><input  type=\"checkbox\" id=\"item-69e01ac2e984f\"><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/189505.xyz\/?p=655\/#%E6%96%87%E6%A1%A3\" title=\"\u6587\u6863\">\u6587\u6863<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/189505.xyz\/?p=655\/#init_cluster\" title=\"init cluster\">init cluster<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/189505.xyz\/?p=655\/#%E9%85%8D%E7%BD%AE%E7%BD%91%E7%BB%9C%E6%8F%92%E4%BB%B6\" title=\"\u914d\u7f6e\u7f51\u7edc\u63d2\u4ef6\">\u914d\u7f6e\u7f51\u7edc\u63d2\u4ef6<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/189505.xyz\/?p=655\/#%E9%83%A8%E7%BD%B2%E5%BA%94%E7%94%A8\" title=\"\u90e8\u7f72\u5e94\u7528\">\u90e8\u7f72\u5e94\u7528<\/a><ul class='ez-toc-list-level-2'><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/189505.xyz\/?p=655\/#%E6%8A%8A%E6%9C%8D%E5%8A%A1%E6%9A%B4%E9%9C%B2%E5%9C%A8%E5%A4%96%E9%9D%A2\" title=\"\u628a\u670d\u52a1\u66b4\u9732\u5728\u5916\u9762\">\u628a\u670d\u52a1\u66b4\u9732\u5728\u5916\u9762<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/189505.xyz\/?p=655\/#%E8%BF%9B%E5%85%A5pod_bash\" title=\"\u8fdb\u5165pod bash\">\u8fdb\u5165pod bash<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"%E6%96%87%E6%A1%A3\"><\/span>\u6587\u6863<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p><a href=\"https:\/\/kubernetes.io\/docs\/setup\/production-environment\/tools\/kubeadm\/create-cluster-kubeadm\/\">https:\/\/kubernetes.io\/docs\/setup\/production-environment\/tools\/kubeadm\/create-cluster-kubeadm\/<\/a><\/p>\n<h1><span class=\"ez-toc-section\" id=\"init_cluster\"><\/span>init cluster<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>\u9700\u8981\u5173\u95edswap,\u4fee\u6539containerd\u914d\u7f6e<\/p>\n<pre><code>swapoff -a\ncontainerd config default &gt; \/etc\/containerd\/config.toml\nvim \/etc\/containerd\/config.toml<\/code><\/pre>\n<p>\u4fee\u6539\u5982\u4e0b\uff08<a href=\"https:\/\/45hrqeao.mirror.aliyuncs.com\u6709\u53ef\u80fd\u9700\u8981\u767b\u9646\u963f\u91cc\u4e91\u63a7\u5236\u53f0\uff0c\u6539\u6210\u81ea\u5df1\u7684\">https:\/\/45hrqeao.mirror.aliyuncs.com\u6709\u53ef\u80fd\u9700\u8981\u767b\u9646\u963f\u91cc\u4e91\u63a7\u5236\u53f0\uff0c\u6539\u6210\u81ea\u5df1\u7684<\/a>\uff09\uff1a<\/p>\n<pre><code>67c67\n&lt;     sandbox_image = &quot;registry.k8s.io\/pause:3.8&quot;\n---\n>     sandbox_image = &quot;registry.aliyuncs.com\/google_containers\/pause:3.10.1&quot;\n139c139\n&lt;             SystemdCgroup = false\n---\n>             SystemdCgroup = true\n170a171,175\n>\n> [plugins.&quot;io.containerd.grpc.v1.cri&quot;.registry.mirrors.&quot;docker.io&quot;]\n> endpoint = [&quot;https:\/\/docker.1ms.run&quot;, &quot;https:\/\/docker-0.unsee.tech&quot;, &quot;https:\/\/registry-1.docker.io&quot;]\n> [plugins.&quot;io.containerd.grpc.v1.cri&quot;.registry.mirrors.&quot;registry.k8s.io&quot;]\n> endpoint = [&quot;https:\/\/45hrqeao.mirror.aliyuncs.com&quot;, &quot;https:\/\/k8s.m.daocloud.io&quot;]\n<\/code><\/pre>\n<p>\u5176\u4e2d\uff0c\u955c\u50cf\u6e90\u90e8\u5206\uff0c\u53c2\u8003https:\/\/comate.baidu.com\/zh\/page\/r7unf9fwsn2<br \/>\n\u7136\u540e\u6267\u884c<\/p>\n<pre><code>\nsudo kubeadm init  --v=5 --image-repository registry.aliyuncs.com\/google_containers<\/code><\/pre>\n<p>\u8f93\u51fa\u7ed3\u679c<\/p>\n<pre><code>\nYour Kubernetes control-plane has initialized successfully!\n\nTo start using your cluster, you need to run the following as a regular user:\n\n  mkdir -p $HOME\/.kube\n  sudo cp -i \/etc\/kubernetes\/admin.conf $HOME\/.kube\/config\n  sudo chown $(id -u):$(id -g) $HOME\/.kube\/config\n\nAlternatively, if you are the root user, you can run:\n\n  export KUBECONFIG=\/etc\/kubernetes\/admin.conf\n\nYou should now deploy a pod network to the cluster.\nRun &quot;kubectl apply -f [podnetwork].yaml&quot; with one of the options listed at:\n  https:\/\/kubernetes.io\/docs\/concepts\/cluster-administration\/addons\/\n\nThen you can join any number of worker nodes by running the following on each as root:\n\nkubeadm join 10.157.101.163:6443 --token yjao5h.mvkmgrs4h36xdehy \\\n        --discovery-token-ca-cert-hash sha256:e8544584ea49315928a34a766cc9532ce2e57ee6bfbbfb9e4d83372366d59a41\n<\/code><\/pre>\n<h1><span class=\"ez-toc-section\" id=\"%E9%85%8D%E7%BD%AE%E7%BD%91%E7%BB%9C%E6%8F%92%E4%BB%B6\"><\/span>\u914d\u7f6e\u7f51\u7edc\u63d2\u4ef6<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>\u53c2\u8003https:\/\/docs.tigera.io\/calico\/latest\/getting-started\/kubernetes\/flannel\/install-for-flannel#installing-with-the-etcd-datastore\uff0c<\/p>\n<h1><span class=\"ez-toc-section\" id=\"%E9%83%A8%E7%BD%B2%E5%BA%94%E7%94%A8\"><\/span>\u90e8\u7f72\u5e94\u7528<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>\u6587\u6863\uff1a<br \/>\nkubectl create deployment kubernetes-bootcamp --image=gcr.io\/google-samples\/kubernetes-bootcamp:v1<br \/>\n\u955c\u50cf\u62c9\u53d6\u5931\u8d25\u7684\uff0c\u67e5\u770b\u539f\u56e0\uff1a<\/p>\n<pre><code>JYTFY-D1-308-H100-D01-3|2025-11-21 06:28:04[like@ k8s]kubectl get pods\nNAME                                   READY   STATUS             RESTARTS   AGE\nkubernetes-bootcamp-658f6cbd58-r9kk4   0\/1     ImagePullBackOff   0          115s\nJYTFY-D1-308-H100-D01-3|2025-11-21 06:29:32[like@ k8s]kubectl describe pod kubernetes-bootcamp-658f6cbd58-r9kk4<\/code><\/pre>\n<p>\u53ef\u4ee5\u6362\u6210docker.io\u7684\u955c\u50cf<\/p>\n<pre><code># \u5220\u9664\u5f53\u524d\u7684 deployment\nkubectl delete deployment kubernetes-bootcamp\n\n# \u4f7f\u7528 Docker Hub \u4e0a\u7684\u955c\u50cf\u91cd\u65b0\u521b\u5efa\nkubectl create deployment kubernetes-bootcamp --image=jocatalin\/kubernetes-bootcamp:v1\n\n# \u67e5\u770b\u65b0\u7684 Pod \u72b6\u6001\nkubectl get pods\n\n# \u67e5\u770b Pod \u8be6\u60c5\nkubectl describe pod kubernetes-bootcamp-&lt;\u65b0\u7684pod-id&gt;<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"%E6%8A%8A%E6%9C%8D%E5%8A%A1%E6%9A%B4%E9%9C%B2%E5%9C%A8%E5%A4%96%E9%9D%A2\"><\/span>\u628a\u670d\u52a1\u66b4\u9732\u5728\u5916\u9762<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<pre><code>kubectl proxy\n\u518d\u5f00\u4e00\u4e2a\u7ec8\u7aef\ncurl http:\/\/localhost:8001\/version\n\nexport POD_NAME=$(kubectl get pods -o go-template --template &#039;{{range .items}}{{.metadata.name}}{{&quot;\\n&quot;}}{{end}}&#039;)\necho Name of the Pod: $POD_NAME\n\ncurl http:\/\/localhost:8001\/api\/v1\/namespaces\/default\/pods\/$POD_NAME:8080\/proxy\/<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"%E8%BF%9B%E5%85%A5pod_bash\"><\/span>\u8fdb\u5165pod bash<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<pre><code>kubectl exec -ti $POD_NAME -- bash<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u6863 https:\/\/kubernetes.io\/docs\/setup\/production-environm &#8230; <a title=\"k8s\u96c6\u7fa4\" class=\"read-more\" href=\"https:\/\/189505.xyz\/?p=655\" aria-label=\"More on k8s\u96c6\u7fa4\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/189505.xyz\/index.php?rest_route=\/wp\/v2\/posts\/655"}],"collection":[{"href":"https:\/\/189505.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/189505.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/189505.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/189505.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=655"}],"version-history":[{"count":14,"href":"https:\/\/189505.xyz\/index.php?rest_route=\/wp\/v2\/posts\/655\/revisions"}],"predecessor-version":[{"id":669,"href":"https:\/\/189505.xyz\/index.php?rest_route=\/wp\/v2\/posts\/655\/revisions\/669"}],"wp:attachment":[{"href":"https:\/\/189505.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=655"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/189505.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=655"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/189505.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=655"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}