{"id":208,"date":"2026-06-08T17:55:40","date_gmt":"2026-06-08T09:55:40","guid":{"rendered":"https:\/\/blog.maoyulong.club\/?p=208"},"modified":"2026-06-08T17:55:41","modified_gmt":"2026-06-08T09:55:41","slug":"homelab-kubernetes-%e5%8d%87%e7%ba%a7%e8%ae%a1%e5%88%92","status":"publish","type":"post","link":"https:\/\/blog.maoyulong.club\/?p=208","title":{"rendered":"HomeLab Kubernetes \u5347\u7ea7\u8ba1\u5212"},"content":{"rendered":"<h2 id=\"\u80cc\u666f\">\u80cc\u666f<\/h2>\n<p>HomeLab \u8fd0\u884c\u7740\u4e00\u4e2a 3 \u8282\u70b9\u7684 kubeadm \u96c6\u7fa4\uff08\u5168\u90e8 control-plane\uff09\uff0c\u627f\u8f7d\u4e86 Harbor\u3001GitLab\u3001WordPress\u3001Longhorn \u5b58\u50a8\u3001Calico \u7f51\u7edc\u7b49\u7ea6 20 \u4e2a\u670d\u52a1\u3002\u96c6\u7fa4\u4ece 2022 \u5e74\u521d\u90e8\u7f72\u540e\u4e00\u76f4\u8fd0\u884c\u5728 K8s v1.22.0\uff0ccontainerd v1.4.3\uff0c\u81f3\u4eca\u5df2\u8d85\u8fc7 4 \u5e74\u672a\u5347\u7ea7\u3002<\/p>\n<p>\u8003\u8651\u5230\u65b0\u7248\u672c\u7684kubesphere\u6700\u4f4e\u652f\u6301\u52301.23\uff0c\u4e14\u540e\u7eed\u5347\u7ea7\u9700\u8981\u9010\u6b65\u5347\u7ea7\u3002<\/p>\n<h3 id=\"k8s-123-\u7684\u5173\u952e\u53d8\u66f4\">K8s 1.23 \u7684\u5173\u952e\u53d8\u66f4<\/h3>\n<figure class=\"table-figure\">\n<table>\n<thead>\n<tr>\n<th>\u53d8\u66f4<\/th>\n<th>\u5f71\u54cd<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>TTLAfterFinished<\/code> feature gate \u5347\u4e3a GA<\/td>\n<td>\u4e0d\u5141\u8bb8\u518d\u901a\u8fc7 <code>--feature-gates<\/code> \u8bbe\u7f6e<\/td>\n<\/tr>\n<tr>\n<td><code>IPv6DualStack<\/code> feature gate \u5347\u4e3a GA<\/td>\n<td>\u540c\u4e0a<\/td>\n<\/tr>\n<tr>\n<td><code>rbac.authorization.k8s.io\/v1alpha1<\/code> \u79fb\u9664<\/td>\n<td>\u6211\u4eec\u5df2\u7528 v1\uff0c\u65e0\u5f71\u54cd<\/td>\n<\/tr>\n<tr>\n<td><code>--experimental-cluster-signing-duration<\/code> \u5e9f\u5f03<\/td>\n<td>\u9700\u6539\u4e3a <code>--cluster-signing-duration<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<h2 id=\"kubeadm-\u5347\u7ea7\u8fc7\u7a0b\">kubeadm \u5347\u7ea7\u8fc7\u7a0b<\/h2>\n<h3 id=\"\u624b\u52a8\u4e8c\u8fdb\u5236\u5347\u7ea7\u6d41\u7a0b\">\u624b\u52a8\u4e8c\u8fdb\u5236\u5347\u7ea7\u6d41\u7a0b<\/h3>\n<p>\u7531\u4e8e\u96c6\u7fa4\u662f\u624b\u52a8\u5b89\u88c5\uff08\u975e apt\uff09\uff0c\u5347\u7ea7\u6b65\u9aa4\uff1a<\/p>\n<pre><code class=\"language-shell\" lang=\"shell\"># 1. \u4e0b\u8f7d\u4e8c\u8fdb\u5236\ncurl -L https:\/\/dl.k8s.io\/release\/v1.23.17\/bin\/linux\/amd64\/kubeadm -o \/root\/kubeadm-1.23.17\ncurl -L https:\/\/dl.k8s.io\/release\/v1.23.17\/bin\/linux\/amd64\/kubelet -o \/root\/kubelet-1.23.17\ncurl -L https:\/\/dl.k8s.io\/release\/v1.23.17\/bin\/linux\/amd64\/kubectl -o \/root\/kubectl-1.23.17\nchmod +x \/root\/kubeadm-1.23.17 \/root\/kubelet-1.23.17 \/root\/kubectl-1.23.17\n\n# 2. \u66ff\u6362 kubeadm\ncp \/root\/kubeadm-1.23.17 \/usr\/bin\/kubeadm\n\n# 3. \u6267\u884c\u5347\u7ea7\nkubeadm upgrade apply v1.23.17 --ignore-preflight-errors=ImagePull\n\n# 4. \u66ff\u6362 kubelet\uff08\u9700\u5148\u505c\u6b62\uff09\nsystemctl stop kubelet\ncp \/root\/kubelet-1.23.17 \/usr\/bin\/kubelet\ncp \/root\/kubectl-1.23.17 \/usr\/bin\/kubectl\nsystemctl daemon-reload\nsystemctl start kubelet\n<\/code><\/pre>\n<h3 id=\"kubeadm-\u7684\u955c\u50cf\u4ed3\u5e93\u53d8\u66f4\">kubeadm \u7684\u955c\u50cf\u4ed3\u5e93\u53d8\u66f4<\/h3>\n<p><strong>\u73b0\u8c61\uff1a<\/strong> <code>kubeadm upgrade apply<\/code> \u5728 preflight \u9636\u6bb5\u5931\u8d25\uff0c\u5c1d\u8bd5\u4ece <code>registry.k8s.io<\/code> \u62c9\u53d6\u955c\u50cf\u8d85\u65f6\u3002<\/p>\n<p><strong>\u539f\u56e0\uff1a<\/strong> kubeadm v1.23.17 \u7684\u53d1\u5e03\u65f6\u95f4\u665a\u4e8e K8s \u955c\u50cf\u4ed3\u5e93\u4ece <code>k8s.gcr.io<\/code> \u8fc1\u79fb\u5230 <code>registry.k8s.io<\/code> \u7684\u65f6\u95f4\u70b9\uff0c\u6240\u4ee5 kubeadm \u4e8c\u8fdb\u5236\u4e2d\u786c\u7f16\u7801\u4e86 <code>registry.k8s.io<\/code> \u4f5c\u4e3a\u9ed8\u8ba4\u4ed3\u5e93\u3002<\/p>\n<p><strong>\u89e3\u51b3\uff1a<\/strong> \u9884\u5148\u4ece\u963f\u91cc\u4e91\u62c9\u53d6\u5e76 tag \u4e3a\u4e24\u4e2a\u5730\u5740\uff1a<\/p>\n<pre><code class=\"language-shell\" lang=\"shell\"># \u4ece\u963f\u91cc\u4e91\u62c9\u53d6\ncrictl pull registry.aliyuncs.com\/google_containers\/kube-apiserver:v1.23.17\n\n# tag \u4e3a registry.k8s.io\uff08kubeadm \u5b9e\u9645\u62c9\u53d6\u7684\u5730\u5740\uff09\nctr -n k8s.io images tag \\\n  registry.aliyuncs.com\/google_containers\/kube-apiserver:v1.23.17 \\\n  registry.k8s.io\/kube-apiserver:v1.23.17\n\n# \u52a0 --ignore-preflight-errors=ImagePull \u8df3\u8fc7\u5728\u7ebf\u62c9\u53d6\u68c0\u67e5\nkubeadm upgrade apply v1.23.17 --yes --ignore-preflight-errors=ImagePull\n<\/code><\/pre>\n<h3 id=\"\u95ee\u9898kubelet-\u4e8c\u8fdb\u5236\u66ff\u6362\u65f6-text-file-busy\">\u95ee\u9898\uff1akubelet \u4e8c\u8fdb\u5236\u66ff\u6362\u65f6 &#8220;Text file busy&#8221;<\/h3>\n<pre><code>cp: cannot create regular file '\/usr\/bin\/kubelet': Text file busy\n<\/code><\/pre>\n<p><strong>\u539f\u56e0\uff1a<\/strong> kubelet \u8fdb\u7a0b\u6b63\u5728\u8fd0\u884c\uff0c\u65e0\u6cd5\u8986\u76d6\u5176\u4e8c\u8fdb\u5236\u6587\u4ef6\u3002<\/p>\n<p><strong>\u89e3\u51b3\uff1a<\/strong> \u5fc5\u987b\u5148\u505c\u6b62 kubelet\uff1a<\/p>\n<pre><code class=\"language-shell\" lang=\"shell\">systemctl stop kubelet\ncp \/root\/kubelet-1.23.17 \/usr\/bin\/kubelet\nsystemctl start kubelet\n<\/code><\/pre>\n<h2 id=\"\u5347\u7ea7\u540ekube-controller-manager\u5361crashloopbackoff\">\u5347\u7ea7\u540ekube-controller-manager\u5361CrashLoopBackOff<\/h2>\n<p>\u5347\u7ea7\u5b8c\u6210\u540e\uff0c\u53d1\u73b0 <strong>kube-controller-manager \u5728\u6240\u6709\u8282\u70b9\u4e0a CrashLoopBackOff<\/strong><\/p>\n<h3 id=\"\u95ee\u98981\u5df2-ga-\u7684-feature-gate-\u4e0d\u53ef\u518d\u8bbe\u7f6e\">\u95ee\u98981\uff1a\u5df2 GA \u7684 Feature Gate \u4e0d\u53ef\u518d\u8bbe\u7f6e<\/h3>\n<p><strong>\u9519\u8bef\uff1a<\/strong> controller-manager \u542f\u52a8\u540e\u7acb\u5373 Fatal \u9000\u51fa\uff08exit code 255\uff09\u3002<\/p>\n<p><strong>\u6839\u56e0\uff1a<\/strong> manifest \u4e2d\u4ecd\u6709 <code>--feature-gates=TTLAfterFinished=true<\/code>\u3002\u5728 K8s 1.23 \u4e2d\uff0c<code>TTLAfterFinished<\/code> \u5df2\u5347\u4e3a GA \u5e76\u9501\u5b9a\u4e3a true\uff0c<strong>\u4e0d\u5141\u8bb8\u901a\u8fc7 feature gate \u518d\u6b21\u663e\u5f0f\u8bbe\u7f6e<\/strong>\u3002<\/p>\n<pre><code class=\"language-shell\" lang=\"shell\"># \u4fee\u590d\uff1a\u5220\u9664\u6240\u6709 GA feature gates\nsed -i '\/--feature-gates=TTLAfterFinished=true\/d' \\\n  \/etc\/kubernetes\/manifests\/kube-controller-manager.yaml \\\n  \/etc\/kubernetes\/manifests\/kube-apiserver.yaml \\\n  \/etc\/kubernetes\/manifests\/kube-scheduler.yaml\n<\/code><\/pre>\n<blockquote><p><strong>\u4e3a\u4ec0\u4e48 kubeadm \u6ca1\u6709\u81ea\u52a8\u6e05\u7406\uff1f<\/strong> \u56e0\u4e3a kubeadm \u5728\u5347\u7ea7 manifest \u65f6\u4f1a\u4fdd\u7559\u7528\u6237\u81ea\u5b9a\u4e49\u7684 extraArgs\u3002\u5982\u679c\u4f60\u624b\u52a8\u6dfb\u52a0\u4e86 feature-gates \u5230 kubeadm-config \u7684 extraArgs \u4e2d\uff0c\u5b83\u4f1a\u539f\u6837\u4fdd\u7559\u3002<\/p><\/blockquote>\n<h3 id=\"\u95ee\u98982\u53cc\u6808-cluster-cidr-\u88ab\u9519\u8bef\u4fee\u6539\">\u95ee\u98982\uff1a\u53cc\u6808 cluster-cidr \u88ab\u9519\u8bef\u4fee\u6539<\/h3>\n<p>\u6e05\u7406 feature gate \u540e\uff0ccontroller-manager \u4ecd\u7136 Fatal\uff1a<\/p>\n<pre><code>error starting controllers: node:masterb has an allocated cidr: fc00::\/64 \nat index:1 that does not exist in cluster cidrs configuration\n<\/code><\/pre>\n<p><strong>\u6839\u56e0\uff1a<\/strong> kubeadm \u5347\u7ea7\u65f6\u5c06 controller-manager \u7684 <code>--cluster-cidr<\/code> \u4ece\u53cc\u6808 <code>100.64.0.0\/10,fc00::\/48<\/code> \u4fee\u6539\u4e3a\u4ec5 IPv4 \u7684 <code>100.64.0.0\/10<\/code>\u3002\u4f46\u8282\u70b9\u5df2\u7ecf\u5206\u914d\u4e86 IPv6 CIDR\uff0c\u9020\u6210\u4e0d\u4e00\u81f4\u3002<\/p>\n<pre><code class=\"language-shell\" lang=\"shell\"># \u4fee\u590d\uff1a\u6062\u590d\u53cc\u6808\u914d\u7f6e\nsed -i 's|--cluster-cidr=100.64.0.0\/10|--cluster-cidr=100.64.0.0\/10,fc00::\/48|' \\\n  \/etc\/kubernetes\/manifests\/kube-controller-manager.yaml\n<\/code><\/pre>\n<blockquote><p><strong>\u6839\u56e0\u63a8\u6d4b\uff1a<\/strong> \u8fd9\u662f\u56e0\u4e3a\u4e4b\u524d <code>--feature-gates=IPv6DualStack=true<\/code> \u88ab\u5220\u9664\u540e\uff0ckubeadm \u8ba4\u4e3a\u4e0d\u518d\u9700\u8981\u53cc\u6808\u914d\u7f6e\uff0c\u81ea\u52a8\u5265\u79bb\u4e86 IPv6 CIDR\u3002<\/p><\/blockquote>\n<h3 id=\"\u95ee\u98983\u4fee\u6539-manifest-\u540e-apiserver-\u6ca1\u6709\u81ea\u52a8\u91cd\u542f\">\u95ee\u98983\uff1a\u4fee\u6539 manifest \u540e apiserver \u6ca1\u6709\u81ea\u52a8\u91cd\u542f<\/h3>\n<p>\u4fee\u6539 static pod manifest \u540e\uff0ckubelet \u5e94\u8be5\u81ea\u52a8\u68c0\u6d4b\u53d8\u66f4\u5e76\u91cd\u542f Pod\u3002\u4f46\u5b9e\u9645\u60c5\u51b5\u662f\uff1a<strong>apiserver \u505c\u6b62\u540e\u6ca1\u6709\u91cd\u542f<\/strong>\u3002<\/p>\n<p><strong>\u539f\u56e0\uff1a<\/strong> kubelet \u505c\u6389\u4e86\u65e7\u7684 apiserver \u5bb9\u5668\uff0c\u4f46\u65b0\u7684 Pod sandbox \u56e0\u4e3a\u67d0\u79cd\u539f\u56e0\u6ca1\u6709\u88ab\u521b\u5efa\uff08containerd \u5c42\u9762\u7684 sandbox \u6b8b\u7559\uff09\u3002<\/p>\n<p><strong>\u89e3\u51b3\uff1a<\/strong> \u624b\u52a8\u6e05\u7406\u65e7\u7684 sandbox \u5bb9\u5668\uff1a<\/p>\n<pre><code class=\"language-shell\" lang=\"shell\"># \u67e5\u770b sandbox\ncrictl pods | grep kube-apiserver-mastera\n# 6d2f74d9e6688  44 hours ago  NotReady  kube-apiserver-mastera\n\n# \u5f3a\u5236\u6e05\u7406\ncrictl stopp 6d2f74d9e6688\ncrictl rmp 6d2f74d9e6688\n\n# kubelet \u4f1a\u5728\u6570\u79d2\u5185\u81ea\u52a8\u521b\u5efa\u65b0\u7684 sandbox \u548c\u5bb9\u5668\n<\/code><\/pre>\n<h2 id=\"\u5347\u7ea7\u540e\u9057\u7559\u95ee\u9898calico-cni-\u6388\u6743\u5931\u8d25\">\u5347\u7ea7\u540e\u9057\u7559\u95ee\u9898\uff1aCalico CNI \u6388\u6743\u5931\u8d25<\/h2>\n<p>\u5347\u7ea7\u5b8c\u6210\u540e\uff0c<strong>\u65b0 Pod \u65e0\u6cd5\u521b\u5efa<\/strong>\uff0c\u62a5\u9519\uff1a<\/p>\n<pre><code>Failed to create pod sandbox: error getting ClusterInformation: \nconnection is unauthorized: Unauthorized\n<\/code><\/pre>\n<h3 id=\"\u6839\u56e0\">\u6839\u56e0<\/h3>\n<p>Calico CNI \u63d2\u4ef6\u5728\u6bcf\u4e2a\u8282\u70b9\u4e0a\u4f7f\u7528\u4e00\u4e2a kubeconfig \u6587\u4ef6\uff08<code>\/etc\/cni\/net.d\/calico-kubeconfig<\/code>\uff09\u6765\u8bbf\u95ee K8s API\u3002\u8fd9\u4e2a kubeconfig \u4e2d\u7684 token \u662f <strong>Pod-bound Service Account Token<\/strong>\uff0c\u7ed1\u5b9a\u5230\u7279\u5b9a\u7684 calico-node Pod UID\u3002<\/p>\n<p>K8s \u5347\u7ea7\u8fc7\u7a0b\u4e2d calico-node Pod \u88ab\u91cd\u5efa\uff0cUID \u6539\u53d8\uff0c\u5bfc\u81f4\u65e7 token \u5931\u6548\u3002\u800c CNI \u662f\u5728 <strong>\u5bb9\u5668 sandbox \u521b\u5efa\u65f6\u88ab kubelet \u8c03\u7528\u7684<\/strong>\uff0c\u6b64\u65f6\u4f7f\u7528\u7684\u662f\u78c1\u76d8\u4e0a\u7684\u9759\u6001 kubeconfig\uff0c\u4e0d\u662f Pod \u5185\u7684\u81ea\u52a8\u6302\u8f7d token\u3002<\/p>\n<h3 id=\"\u89e3\u51b3\">\u89e3\u51b3<\/h3>\n<p>\u91cd\u542f calico-node DaemonSet\uff0c\u8ba9\u65b0 Pod \u5199\u5165\u65b0\u7684 CNI kubeconfig\uff1a<\/p>\n<pre><code class=\"language-shell\" lang=\"shell\">kubectl rollout restart ds calico-node -n kube-system\n\n# \u5982\u679c\u65e7 Pod \u56e0\u4e3a Calico \u95ee\u9898\u65e0\u6cd5\u6b63\u5e38\u7ec8\u6b62\uff0c\u5f3a\u5236\u5220\u9664\nkubectl delete pod calico-node-xxxx -n kube-system --force --grace-period=0\n\n# \u9a8c\u8bc1\u65b0 kubeconfig \u5df2\u66f4\u65b0\nls -la \/etc\/cni\/net.d\/calico-kubeconfig\n# \u786e\u8ba4\u65f6\u95f4\u6233\u662f\u6700\u65b0\u7684\n<\/code><\/pre>\n<blockquote><p><strong>\u5173\u952e\u70b9\uff1a<\/strong> \u8fd9\u4e2a\u95ee\u9898\u4e0d\u4f1a\u5728\u5347\u7ea7\u65f6\u7acb\u5373\u66b4\u9732\uff0c\u56e0\u4e3a\u5df2\u6709\u7684 Pod \u4e0d\u53d7\u5f71\u54cd\u3002\u53ea\u6709\u5728\u521b\u5efa<strong>\u65b0 Pod<\/strong> \u65f6\u624d\u4f1a\u89e6\u53d1 CNI \u8c03\u7528\u5e76\u66b4\u9732 token \u5931\u6548\u95ee\u9898\u3002<\/p><\/blockquote>\n<h2 id=\"\u6700\u7ec8\u72b6\u6001\">\u6700\u7ec8\u72b6\u6001<\/h2>\n<pre><code>NAME      STATUS   ROLES                  VERSION\nmastera   Ready    control-plane,master   v1.23.17\nmasterb   Ready    control-plane,master   v1.23.17\nmasterc   Ready    control-plane,master   v1.23.17\n<\/code><\/pre>\n<p>\u6240\u6709\u670d\u52a1\u6b63\u5e38\u8fd0\u884c\uff0cCalico \u7f51\u7edc\u901a\u4fe1\u6b63\u5e38\uff0cLonghorn \u5b58\u50a8\u65e0\u5f71\u54cd\u3002\u4e0b\u4e00\u6b65\u5c06\u7ee7\u7eed\u5347\u7ea7\u5230 1.24\uff0c\u5c4a\u65f6\u9700\u8981\u9762\u5bf9 containerd CRI v1alpha2 \u5e9f\u5f03\u548c dockershim \u79fb\u9664\u7684\u6311\u6218\u3002<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u80cc\u666f HomeLab \u8fd0\u884c\u7740\u4e00\u4e2a 3 \u8282\u70b9\u7684 kubeadm \u96c6\u7fa4\uff08\u5168\u90e8 control-plane\uff09\uff0c\u627f\u8f7d\u4e86 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":209,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-208","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.maoyulong.club\/index.php?rest_route=\/wp\/v2\/posts\/208","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.maoyulong.club\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.maoyulong.club\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.maoyulong.club\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.maoyulong.club\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=208"}],"version-history":[{"count":1,"href":"https:\/\/blog.maoyulong.club\/index.php?rest_route=\/wp\/v2\/posts\/208\/revisions"}],"predecessor-version":[{"id":210,"href":"https:\/\/blog.maoyulong.club\/index.php?rest_route=\/wp\/v2\/posts\/208\/revisions\/210"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.maoyulong.club\/index.php?rest_route=\/wp\/v2\/media\/209"}],"wp:attachment":[{"href":"https:\/\/blog.maoyulong.club\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=208"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.maoyulong.club\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=208"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.maoyulong.club\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=208"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}