树莓派搭建k3s

树莓派安装 k3s

1.安装 k3s

控制节点

1    curl -sfL https://get.k3s.io | sh -
2    cat /var/lib/rancher/k3s/server/node-token

工作节点

1    curl -sfL https://get.k3s.io | K3S_URL=https://myserver:6443 K3S_TOKEN=mynodetoken sh -

树莓派特别要注意一个坑,就是关于内存的问题这个之后再讲

1    k3s kubectl get nodes
2    #显示正确的节点表示完成

卸载 k3s

1    #server 节点
2    /usr/local/bin/k3s-uninstall.sh
3    #agent 节点
4    /usr/local/bin/k3s-agent-uninstall.sh

2.安装 dashboard k3s 面板

部署 Kubernetes 仪表盘

1    GITHUB_URL=https://github.com/kubernetes/dashboard/releases
2    VERSION_KUBE_DASHBOARD=$(curl -w '%{url_effective}' -I -L -s -S ${GITHUB_URL}/latest -o /dev/null | sed -e 's|.*/||')
3    sudo k3s kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/${VERSION_KUBE_DASHBOARD}/aio/deploy/recommended.yaml

仪表盘 RBAC 配置

创建以下资源清单文件:

dashboard.admin-user.yml

1apiVersion: v1
2kind: ServiceAccount
3metadata:
4  name: admin-user
5  namespace: kubernetes-dashboard

dashboard.admin-user-role.yml

 1apiVersion: rbac.authorization.k8s.io/v1
 2kind: ClusterRoleBinding
 3metadata:
 4  name: admin-user
 5roleRef:
 6  apiGroup: rbac.authorization.k8s.io
 7  kind: ClusterRole
 8  name: cluster-admin
 9subjects:
10  - kind: ServiceAccount
11    name: admin-user
12    namespace: kubernetes-dashboard

部署 admin-user 配置:

1    sudo k3s kubectl create -f dashboard.admin-user.yml -f dashboard.admin-user-role.yml

获得 Bearer Token

1    sudo k3s kubectl -n kubernetes-dashboard describe secret admin-user-token | grep '^token'

现在可以通过以下网址访问仪表盘:

1    sudo k3s kubectl proxy

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

连接 lens

1    cat /etc/rancher/k3s/k3s.yaml
2    更改本地host
3    穿透服务器IP    local

3.安装 kube—prometheus 监控

一键安装

1    wget https://github.com/prometheus-operator/kube-prometheus/archive/refs/tags/v0.9.0.tar.gz
2    tar -zxvf v0.9.0.tar.gz
3    cd kube-prometheus-0.9.0/manifests
4    k3s kubectl apply -f setup/
5    k3s kubectl get pod -n monitoring
6    k3s kubectl apply -f .

一键卸载

1    cd kube-prometheus/manifests
2    k3s kubectl delete -f .
3    k3s kubectl delete -f setup/

4.安装 nfs 外部驱动挂载 storageclass

5.创建有状态 pods(mysql)