背景:

树莓派结点,想要实现数据传输、负载查看的功能。现在想用k3s构建集群+dashboard实现网页。第一次弄,记录一下。

过程:

第一步:编辑 /boot/cmdline.txt,在末尾添加 cgroup_memory=1 cgroup_enable=memory。

因为不配置 下载时会报错,[INFO] Failed to find memory cgroup, you may need to add “cgroup_memory=1 cgroup_enable=memory” to your linux cmdline (/boot/cmdline.txt on a Raspberry Pi)

具体操作:

因为这个文件是默认不允许修改的,所以先进入root角色,命令为sudo su

vi /boot/cmdline.txt

输入i表示输入

粘贴可以用shift+右键,选择paste。

编辑完点esc键

输入:wq!,表示强制保存退出。

如果没有vim,就用nano控制

sudo nano /boot/cmdline.txt

cgroup_memory=1 cgroup_enable=memory

ctrl+o 保存,enter保存文件名,ctrl+x退出。

第二步:因为只有windows能科学上网,其他树莓派用代理上网。参见

树莓派用别的主机上网-CSDN博客

有国内镜像下载,仍然用科学上网原因:

所有节点都是ContainerCreating状态

kubectl get pods -A
 

NAMESPACE              NAME                                         READY   STATUS              RESTARTS   AGE
kube-system            coredns-576bfc4dc7-zlsh8                     0/1     ContainerCreating   0          5d5h
kube-system            helm-install-traefik-6crzs                   0/1     ContainerCreating   0          5d5h
kube-system            helm-install-traefik-crd-nwqmj               0/1     ContainerCreating   0          5d5h
kube-system            local-path-provisioner-6795b5f9d8-wnk4d      0/1     ContainerCreating   0          5d5h
kube-system            metrics-server-557ff575fb-6jcjx              0/1     ContainerCreating   0          5d5h
kubernetes-dashboard   dashboard-metrics-scraper-795895d745-l9llg   0/1     ContainerCreating   0          30h
kubernetes-dashboard   kubernetes-dashboard-56cf4b97c5-d5szf        0/1     ContainerCreating   0          30h

究其原因:

failed to pull and unpack image "docker.io/rancher/mirrored-pause:3.6"

下载后会有镜像拉取失败。

第三步:使用国内镜像下载k3s

master下载命令:

curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn K3S_KUBECONFIG_OUTPUT=/root/.kube/config sh -

(这里我看可以选择用docker做容器,我都没用过,所以没选)

添加worker节点:

1.在master节点输入

sudo cat /var/lib/rancher/k3s/server/node-token

获取token。

2.ssh进入worker节点, 

curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn K3S_URL=https://master在局域网的ip地址:6443 K3S_TOKEN=刚才获取到的token sh -

这里的https://rancher-mirror.rancher.cn/k3s/k3s-install.sh网址我是替换了可访问的,如果输入命令后没反应,大概就是网站无法访问。

worker节点加入后,在master节点输入k3s kubectl get node


NAME           STATUS   ROLES                  AGE     VERSION
c1-0           Ready    control-plane,master   6h8m    v1.30.3+k3s1
c1-1-rpi3b-2   Ready    <none>                 29s     v1.30.3+k3s1
c1-1-rpi4b-1   Ready    <none>                 4m57s   v1.30.3+k3s1

第四步:使用kubectl get pods --all-namespaces报错,


E0807 22:24:59.741366  374505 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused
E0807 22:24:59.742873  374505 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused
E0807 22:24:59.744160  374505 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused
E0807 22:24:59.745814  374505 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused
E0807 22:24:59.748474  374505 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused
The connection to the server localhost:8080 was refused - did you specify the right host or port?

1.用kubectl get nodes -v=10,使用 kubectl 命令行工具来获取 Kubernetes 集群中所有节点的详细信息
The connection to the server localhost:8080 was refused - did you specify the right host or port?
看到报的大概还是connection refused

2.kubectl config view,用于查看当前用户的 Kubernetes 配置信息的命令

apiVersion: v1
clusters: null
contexts: null
current-context: ""
kind: Config
preferences: {}
users: null
 

3.网上搜了stat /var/lib/rancher/k3s/server/node-token这个命令,not work。

4.

mkdir /etc/rancher/k3s/

 k3s.yaml
把master节点的, k3s.yaml传过来

把cluster里的

server: https://127.0.0.1:6443
改成

server: https://主机ip:6443

传文件命令:

scp /etc/rancher/k3s/k3s.yaml pi@192.168.1.8:/etc/rancher/k3s/
即为 scp 文件 接受树莓派名@ip:路径

传输可能会遇到 Permission denied

原因是权限不够,

传输主机执行:chmod 777 /etc/rancher/k3s/k3s.yaml

接收主机执行:chmod 777 /etc/rancher/k3s/

常见命令:

1.卸载重新安装命令

master:

sh /usr/local/bin/k3s-uninstall.sh

node:

/usr/local/bin/k3s-agent-uninstall.sh

再安装好,此时输入k3s kubectl get node
NAME   STATUS   ROLES                  AGE     VERSION
c1-0   Ready    control-plane,master   4h51m   v1.30.3+k3s1


 

下载dashboard:

这里没详细记录

root@c1-0:/home/work/k3s-dashboard# wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml
--2024-08-15 23:25:22--  https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 0.0.0.0, ::
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|0.0.0.0|:443... failed: Connection refused.
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|::|:443... failed: Connection refused.
 

[root@master ~]# vi /etc/hosts

185.199.110.133 raw.githubusercontent.com

root@c1-0:/home/work/k3s-dashboard# wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0/aio/deploy/recommended.yaml
--2024-08-15 23:28:31--  https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0/aio/deploy/recommended.yaml
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.110.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.110.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7552 (7.4K) [text/plain]
Saving to: ‘recommended.yaml’

recommended.yaml                                        100%[=============================================================================================================================>]   7.38K  21.4KB/s    in 0.3s

2024-08-15 23:28:32 (21.4 KB/s) - ‘recommended.yaml’ saved [7552/7552]

获取token 

kubectl -n kubernetes-dashboard create token admin-user

http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/#/login

kubectl proxy

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐