<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>K3s on 我的个人博客</title>
        <link>https://liangjinzhi.com/categories/k3s/</link>
        <description>Recent content in K3s on 我的个人博客</description>
        <generator>Hugo -- gohugo.io</generator>
        <language>zh-cn</language>
        <lastBuildDate>Mon, 29 Jun 2026 09:19:11 +0000</lastBuildDate><atom:link href="https://liangjinzhi.com/categories/k3s/index.xml" rel="self" type="application/rss+xml" /><item>
            <title>【K3s 系列 01】从零搭建 K3s</title>
            <link>https://liangjinzhi.com/k3s-01/</link>
            <pubDate>Mon, 29 Jun 2026 09:19:11 +0000</pubDate>
            <guid>https://liangjinzhi.com/k3s-01/</guid>
            <description>&lt;h2 id=&#34;一获取系统基础硬件信息&#34;&gt;一、获取系统基础硬件信息&#xA;&lt;/h2&gt;&lt;p&gt;&lt;code&gt;#基础架构 （输出参考：如果是 x86_64 或 aarch64，即可完美支持。）&#xA;pig@vm-debian-13:~$ uname -m&#xA;x86_64&lt;/p&gt;&#xA;&lt;p&gt;#处理器 （K3s 单节点极其轻量，最低仅需 1核 CPU 和 512MB 内存（推荐 1核1G 以上）。）&#xA;pig@vm-debian-13:~$ lscpu | grep -E &amp;ldquo;Model name|CPU(s):&amp;rdquo;&#xA;CPU(s):                                  2&#xA;Model name:                              13th Gen Intel(R) Core(TM) i5-13400&#xA;NUMA node0 CPU(s):                       0,1&lt;/p&gt;&#xA;&lt;p&gt;#内存大小&#xA;pig@vm-debian-13:~$ free -m&#xA;total        used        free      shared  buff/cache   available&#xA;Mem:            3883         886        1917           0        1334        2997&#xA;Swap:              0           0   &lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;安装脚本&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;官方的脚本太慢，国内用户使用这个脚本进行加速&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$ curl -sfL &lt;a class=&#34;link&#34; href=&#34;https://rancher-mirror.rancher.cn/k3s/k3s-install.sh&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;https://rancher-mirror.rancher.cn/k3s/k3s-install.sh&lt;/a&gt; | INSTALL_K3S_MIRROR=cn sh -&lt;/code&gt;&lt;/pre&gt;&lt;figure class=&#34;wp-block-image size-full&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;img loading=&#34;lazy&#34; decoding=&#34;async&#34; width=&#34;1238&#34; height=&#34;505&#34; src=&#34;https://liangjinzhi.com/wp-content/uploads/2026/06/image-74.png&#34; alt=&#34;&#34; class=&#34;wp-image-340&#34; /&gt; &lt;/figure&gt;&lt;/p&gt;&#xA;&lt;p&gt;检查k3s服务状态&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$ systemctl status k3s&lt;/code&gt;&lt;/pre&gt;&lt;figure class=&#34;wp-block-image size-full&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;img loading=&#34;lazy&#34; decoding=&#34;async&#34; width=&#34;858&#34; height=&#34;270&#34; src=&#34;http://liangjinzhi.com/wp-content/uploads/2026/06/image-32.png&#34; alt=&#34;&#34; class=&#34;wp-image-147&#34; srcset=&#34;https://liangjinzhi.com/wp-content/uploads/2026/06/image-32.png 858w, https://liangjinzhi.com/wp-content/uploads/2026/06/image-32-300x94.png 300w, https://liangjinzhi.com/wp-content/uploads/2026/06/image-32-768x242.png 768w&#34; sizes=&#34;auto, (max-width: 858px) 100vw, 858px&#34; /&gt; &lt;/figure&gt;&lt;/p&gt;&#xA;&lt;p&gt;查看集群节点状态&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$ sudo kubectl get node&lt;/code&gt;&lt;/pre&gt;&lt;figure class=&#34;wp-block-image size-full&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;img loading=&#34;lazy&#34; decoding=&#34;async&#34; width=&#34;816&#34; height=&#34;64&#34; src=&#34;http://liangjinzhi.com/wp-content/uploads/2026/06/image-33.png&#34; alt=&#34;&#34; class=&#34;wp-image-148&#34; srcset=&#34;https://liangjinzhi.com/wp-content/uploads/2026/06/image-33.png 816w, https://liangjinzhi.com/wp-content/uploads/2026/06/image-33-300x24.png 300w, https://liangjinzhi.com/wp-content/uploads/2026/06/image-33-768x60.png 768w&#34; sizes=&#34;auto, (max-width: 816px) 100vw, 816px&#34; /&gt; &lt;/figure&gt;&lt;/p&gt;&#xA;&lt;p&gt;查看集群中运行的pod&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$ sudo kubectl get pods -A&lt;/code&gt;&lt;/pre&gt;&lt;figure class=&#34;wp-block-image size-full&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;img loading=&#34;lazy&#34; decoding=&#34;async&#34; width=&#34;942&#34; height=&#34;135&#34; src=&#34;http://liangjinzhi.com/wp-content/uploads/2026/06/image-34.png&#34; alt=&#34;&#34; class=&#34;wp-image-149&#34; srcset=&#34;https://liangjinzhi.com/wp-content/uploads/2026/06/image-34.png 942w, https://liangjinzhi.com/wp-content/uploads/2026/06/image-34-300x43.png 300w, https://liangjinzhi.com/wp-content/uploads/2026/06/image-34-768x110.png 768w&#34; sizes=&#34;auto, (max-width: 942px) 100vw, 942px&#34; /&gt; &lt;/figure&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://docs.k3s.io/zh/quick-start&#34; data-type=&#34;link&#34; data-id=&#34;https://docs.k3s.io/zh/quick-start&#34;&gt;K3s 官方经典架构与安装文档&lt;/a&gt;&lt;/p&gt;&#xA;&lt;h2 id=&#34;二配置kubectl-普通用户&#34;&gt;二、配置kubectl （普通用户）&#xA;&lt;/h2&gt;&lt;p&gt;普通用户执行命令 &lt;em&gt;&lt;kbd&gt;kubectl get nodes&lt;/kbd&gt;&lt;/em&gt; 提示没有权限&lt;/p&gt;&#xA;&lt;figure class=&#34;wp-block-image size-full&#34;&gt;&#xA;&lt;p&gt;&lt;img loading=&#34;lazy&#34; decoding=&#34;async&#34; width=&#34;934&#34; height=&#34;127&#34; src=&#34;http://liangjinzhi.com/wp-content/uploads/2026/06/image-35.png&#34; alt=&#34;&#34; class=&#34;wp-image-151&#34; srcset=&#34;https://liangjinzhi.com/wp-content/uploads/2026/06/image-35.png 934w, https://liangjinzhi.com/wp-content/uploads/2026/06/image-35-300x41.png 300w, https://liangjinzhi.com/wp-content/uploads/2026/06/image-35-768x104.png 768w&#34; sizes=&#34;auto, (max-width: 934px) 100vw, 934px&#34; /&gt; &lt;/figure&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;pig@vm-debian:~$ mkdir -p &lt;del&gt;/.kube   #创建 .kube 目录&#xA;pig@vm-debian:&lt;/del&gt;$ sudo cp /etc/rancher/k3s/k3s.yaml  &lt;del&gt;/.kube/config #复制 K3s 默认配置&#xA;pig@vm-debian:&lt;/del&gt;$ sudo chown $USER:$USER &lt;del&gt;/.kube/config #修改文件所属用户&#xA;pig@vm-debian:&lt;/del&gt;$ echo &amp;rsquo;export KUBECONFIG=$HOME/.kube/config&amp;rsquo; &amp;gt;&amp;gt; ~/.bashrc #配置环境变量&#xA;source &lt;del&gt;/.bashrc&#xA;pig@vm-debian:&lt;/del&gt;$ kubectl get nodes #验证配置&#xA;NAME           STATUS   ROLES           AGE    VERSION&#xA;vm-debian-13   Ready    control-plane   175m   v1.35.5+k3s1&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&#xA;&lt;p&gt;如上，说明当前普通用户已经可以正常访问 Kubernetes API。&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;运维思考&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;生产环境中，不建议长期使用root用户进行Kubernetes管理。&lt;/p&gt;&#xA;&lt;p&gt;推荐使用普通用户，通过 &lt;kbd&gt;sudo&lt;/kbd&gt; 执行系统级操作（如管理服务、修改配置），而将 &lt;kbd&gt;kubectl&lt;/kbd&gt; 配置为普通用户直接使用。&lt;/p&gt;&#xA;&lt;p&gt;这样既符合Linux最小权限原则，也更符合企业运维的实际工作方式。&lt;/p&gt;&#xA;&lt;h2 id=&#34;三配置dashboard&#34;&gt;三、配置dashboard&#xA;&lt;/h2&gt;&lt;p&gt;为了避免下载失败的情况，这里使用国内可访问的镜像仓库&lt;/p&gt;&#xA;&lt;h3 id=&#34;31下载yaml&#34;&gt;3.1下载YAML&#xA;&lt;/h3&gt;&lt;p&gt;&lt;code&gt;wget &lt;a class=&#34;link&#34; href=&#34;https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml&lt;/a&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&#xA;&lt;h3 id=&#34;32修改类似内容&#34;&gt;3.2修改类似内容&#xA;&lt;/h3&gt;&lt;p&gt;&lt;code&gt;找到类似内容：&lt;/p&gt;&#xA;&lt;p&gt;image: kubernetesui/dashboard:v2.7.0&lt;/p&gt;&#xA;&lt;p&gt;改成（示例）：&lt;/p&gt;&#xA;&lt;p&gt;image: docker.m.daocloud.io/kubernetesui/dashboard:v2.7.0&lt;/p&gt;&#xA;&lt;p&gt;再找到：&lt;/p&gt;&#xA;&lt;p&gt;image: kubernetesui/metrics-scraper:v1.0.8&lt;/p&gt;&#xA;&lt;p&gt;改成：&lt;/p&gt;&#xA;&lt;p&gt;image: docker.m.daocloud.io/kubernetesui/metrics-scraper:v1.0.8&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&#xA;&lt;h3 id=&#34;33开始部署&#34;&gt;3.3开始部署&#xA;&lt;/h3&gt;&lt;p&gt;&lt;code&gt;$ kubectl apply -f recommended.yaml&#xA;namespace/kubernetes-dashboard unchanged&#xA;serviceaccount/kubernetes-dashboard unchanged&#xA;service/kubernetes-dashboard unchanged&#xA;secret/kubernetes-dashboard-certs unchanged&#xA;secret/kubernetes-dashboard-csrf unchanged&#xA;secret/kubernetes-dashboard-key-holder unchanged&#xA;configmap/kubernetes-dashboard-settings unchanged&#xA;role.rbac.authorization.k8s.io/kubernetes-dashboard unchanged&#xA;clusterrole.rbac.authorization.k8s.io/kubernetes-dashboard unchanged&#xA;rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard unchanged&#xA;clusterrolebinding.rbac.authorization.k8s.io/kubernetes-dashboard unchanged&#xA;deployment.apps/kubernetes-dashboard configured&#xA;service/dashboard-metrics-scraper unchanged&#xA;deployment.apps/dashboard-metrics-scraper configured&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&#xA;&lt;p&gt;3.4验证是否成功&lt;/p&gt;&#xA;&lt;p&gt;这里有2个之前创建创建的pod&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$ kubectl get pods -n kubernetes-dashboard&#xA;NAME                                         READY   STATUS              RESTARTS   AGE&#xA;dashboard-metrics-scraper-7764d6f57c-r26sm   0/1     ContainerCreating   0          13m&#xA;dashboard-metrics-scraper-8d46b45f6-4c6bv    0/1     ContainerCreating   0          23h&#xA;kubernetes-dashboard-659cf4fdd5-l2gp9        0/1     ContainerCreating   0          13m&#xA;kubernetes-dashboard-b44857bbb-9k9kc         0/1     ContainerCreating   0          23h&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&#xA;&lt;p&gt;这里READY一直是0，失败了，需要 排查一下。&lt;/p&gt;&#xA;&lt;p&gt;查看pod卡在哪里了&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;kubectkubectl describe pod -n kubernetes-dashboard-659cf4fdd5-l2gp9&#xA;No resources found in kubernetes-dashboard-659cf4fdd5-l2gp9 namespace.&#xA;pig@vm-debian:&lt;del&gt;$&#xA;pig@vm-debian:&lt;/del&gt;$ kubectl describe pod -n kubernetes-dashboard dashboard-metrics-scraper-7764d6f57c-r26sm |tail&#xA;Warning  FailedCreatePodSandBox  17m                 kubelet            Failed to create pod sandbox: rpc error: code = DeadlineExceeded desc = failed to start sandbox &amp;ldquo;74e4795e553dc82c49e53c89a724293525e65e3134fa2ae09787ff197831d938&amp;rdquo;: failed to get sandbox image &amp;ldquo;rancher/mirrored-pause:3.6&amp;rdquo;: failed to pull image &amp;ldquo;rancher/mirrored-pause:3.6&amp;rdquo;: failed to pull and unpack image &amp;ldquo;docker.io/rancher/mirrored-pause:3.6&amp;rdquo;: failed to resolve reference &amp;ldquo;docker.io/rancher/mirrored-pause:3.6&amp;rdquo;: failed to do request: Head &amp;ldquo;&lt;a class=&#34;link&#34; href=&#34;https://registry-1.docker.io/v2/rancher/mirrored-pause/manifests/3.6%22&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;https://registry-1.docker.io/v2/rancher/mirrored-pause/manifests/3.6&#34;&lt;/a&gt;: dial tcp 182.50.139.56:443: i/o timeout-n kubernetes-dashboard-659cf4fdd5-l2gp9&#xA;No resources found in kubernetes-dashboard-659cf4fdd5-l2gp9 namespace.&#xA;pig@vm-debian:&lt;del&gt;$&#xA;pig@vm-debian:&lt;/del&gt;$ kubectl describe pod -n kubernetes-dashboard dashboard-metrics-scraper-7764d6f57c-r26sm |tail&#xA;Warning  FailedCreatePodSandBox  17m                 kubelet            Failed to create pod sandbox: rpc error: code = DeadlineExceeded desc = failed to start sandbox &amp;ldquo;74e4795e553dc82c49e53c89a724293525e65e3134fa2ae09787ff197831d938&amp;rdquo;: failed to get sandbox image &amp;ldquo;rancher/mirrored-pause:3.6&amp;rdquo;: failed to pull image &amp;ldquo;rancher/mirrored-pause:3.6&amp;rdquo;: failed to pull and unpack image &amp;ldquo;docker.io/rancher/mirrored-pause:3.6&amp;rdquo;: failed to resolve reference &amp;ldquo;docker.io/rancher/mirrored-pause:3.6&amp;rdquo;: failed to do request: Head &amp;ldquo;&lt;a class=&#34;link&#34; href=&#34;https://registry-1.docker.io/v2/rancher/mirrored-pause/manifests/3.6%22&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;&#xA;    &gt;https://registry-1.docker.io/v2/rancher/mirrored-pause/manifests/3.6&#34;&lt;/a&gt;: dial tcp 182.50.139.56:443: i/o timeout&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&#xA;&lt;p&gt;Kubernetes 无法拉取 pause 镜像（sandbox基础镜像）&lt;/p&gt;&#xA;&lt;p&gt;解决方案：&lt;/p&gt;&#xA;&lt;code&gt;&#xA;#修改 K3s 的 pause 镜像&#xA;$ sudo vi  /etc/rancher/k3s/registries.yaml #编辑以下文件&#xA;mirrors:&#xA;  docker.io:&#xA;    endpoint:&#xA;      - &#34;https://docker.m.daocloud.io&#34;&#xA;&lt;p&gt;#然后进行重启&#xA;$sudo systemctl restart k3s&lt;/p&gt;&#xA;&lt;p&gt;$ kubectl get pods -n kubernetes-dashboard  #这个时候已经创建成功了&#xA;NAME                                         READY   STATUS    RESTARTS        AGE&#xA;dashboard-metrics-scraper-7764d6f57c-r26sm   1/1     Running   0               28m&#xA;kubernetes-dashboard-659cf4fdd5-l2gp9        1/1     Running   1 (2m45s ago)   28m&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&#xA;&lt;p&gt;3.4配置Dashboard进行访问&lt;/p&gt;&#xA;&lt;p&gt;可以通过 kubectl proxy，或者配置NodePort进行进行访问。&lt;/p&gt;&#xA;&lt;p&gt;我们这里通过配置NodePort来继续。&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$kubectl edit svc -n kubernetes-dashboard kubernetes-dashboard&#xA;#找到：&#xA;type: ClusterIP&#xA;#修改成&#xA;type: NodePort&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&#xA;&lt;p&gt;$kubectl get svc -n kubernetes-dashboard #查看端口&lt;/p&gt;&#xA;&lt;figure class=&#34;wp-block-image size-full&#34;&gt;&#xA;&lt;p&gt;&lt;img loading=&#34;lazy&#34; decoding=&#34;async&#34; width=&#34;1020&#34; height=&#34;130&#34; src=&#34;https://liangjinzhi.com/wp-content/uploads/2026/06/image-71.png&#34; alt=&#34;&#34; class=&#34;wp-image-336&#34; /&gt; &lt;/figure&gt;&lt;/p&gt;&#xA;&lt;p&gt;主机访问：https://ip:port&lt;/p&gt;&#xA;&lt;figure class=&#34;wp-block-image size-full&#34;&gt;&#xA;&lt;p&gt;&lt;img loading=&#34;lazy&#34; decoding=&#34;async&#34; width=&#34;1495&#34; height=&#34;606&#34; src=&#34;https://liangjinzhi.com/wp-content/uploads/2026/06/image-72.png&#34; alt=&#34;&#34; class=&#34;wp-image-337&#34; /&gt; &lt;/figure&gt;&lt;/p&gt;&#xA;&lt;p&gt;生成token&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;$ kubectl -n kubernetes-dashboard create token admin-user&#xA;eyJhbGciOiJSUz&amp;hellip;..qGeyA  #这里进行省略输出&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&#xA;&lt;p&gt;获取token并进行登录&lt;/p&gt;&#xA;&lt;figure class=&#34;wp-block-image size-full&#34;&gt;&#xA;&lt;p&gt;&lt;img loading=&#34;lazy&#34; decoding=&#34;async&#34; width=&#34;2538&#34; height=&#34;994&#34; src=&#34;https://liangjinzhi.com/wp-content/uploads/2026/06/image-73.png&#34; alt=&#34;&#34; class=&#34;wp-image-338&#34; /&gt; &lt;/figure&gt;&lt;/p&gt;&#xA;&lt;p&gt;至此，K3s 单节点环境已完成基础验证，包括：&lt;/p&gt;&#xA;&lt;ul class=&#34;wp-block-list&#34;&gt;&#xA;  &lt;li&gt;&#xA;    kubectl 可用&#xA;  &lt;/li&gt;&#xA;  &lt;li&gt;&#xA;    Pod 正常运行&#xA;  &lt;/li&gt;&#xA;  &lt;li&gt;&#xA;    Dashboard 可访问并登录成功&#xA;  &lt;/li&gt;&#xA;&lt;/ul&gt;</description>
        </item></channel>
</rss>
