前言
想部署一个k8s实验环境
看了很多 minikube kind k3s 发现还是rancher的k3s对资源要求少
部署
部署k3s
k3s 本质上就是一个独立的可执行文件 包含整个k8s的manager的组件
大于1g的内存和能访问github站点的权限和安装好docker
https://rancher.com/docs/k3s/latest/en/installation/install-options/
1 | 官方脚本部署 |
安装k8s-dashboard
https://rancher.com/docs/k3s/latest/en/installation/kube-dashboard/
安装dashboard
1
2
3GITHUB_URL=https://github.com/kubernetes/dashboard/releases
VERSION_KUBE_DASHBOARD=$(curl -w '%{url_effective}' -I -L -s -S ${GITHUB_URL}/latest -o /dev/null | sed -e 's|.*/||')
sudo k3s kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/${VERSION_KUBE_DASHBOARD}/aio/deploy/recommended.yaml创建rbac角色权限配置
dashboard.admin-user.yml1
2
3
4
5apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kubernetes-dashboarddashboard.admin-user-role.yml
1
2
3
4
5
6
7
8
9
10
11
12apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: admin-user
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin-user
namespace: kubernetes-dashboard
部署配置和生成token
1 | 部署角色权限配置 |
通过转发代理配置远程访问
https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/
https://segmentfault.com/a/1190000023130407
1 | 查看部署的service的端口 |
升级仪表板链接
1
2
3
4sudo k3s kubectl delete ns kubernetes-dashboard
GITHUB_URL=https://github.com/kubernetes/dashboard/releases
VERSION_KUBE_DASHBOARD=$(curl -w '%{url_effective}' -I -L -s -S ${GITHUB_URL}/latest -o /dev/null | sed -e 's|.*/||')
sudo k3s kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/${VERSION_KUBE_DASHBOARD}/aio/deploy/recommended.yaml -f dashboard.admin-user.yml -f dashboard.admin-user-role.yml删除仪表板和管理员用户配置链接
1
2
3sudo k3s kubectl delete ns kubernetes-dashboard
sudo k3s kubectl delete clusterrolebinding kubernetes-dashboard
sudo k3s kubectl delete clusterrole kubernetes-dashboard
安装接入helm
k3s当前版本使用最新的helm即可
https://helm.sh/docs/
- 安装helm
https://helm.sh/docs/intro/install/
服务器版本是ubuntu
1 | curl https://baltocdn.com/helm/signing.asc | sudo apt-key add - |
- 设置KUBECONFIG变量
直接设置在当前shell或者写入 .bashrc .zshrc之类的地方都可以 只要当前shell 有KUBECONFIG变量就行
1
2
3export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
echo $KUBECONFIG
helm list -A
安装示例应用
k8s 安装各种应用 可以直接去编写 yaml来实现 也可以直接使用helm这种工具
这里演示 就直接使用helm来
1 | 添加指定仓库 |
总结
k3s 总体安装使用 感觉还行 符合我的预期
简单粗暴 然后和k8s 区别不大