Centos 快速安装配置K3S
免费视频教程
https://study.163.com/course/courseLearn.htm?courseId=1209568805#/learn/video?lessonId=1279885390&courseId=1209568805
官方文档(中文)
https://rancher2.docs.rancher.cn/docs/k3s/installation/_index
docker 安装
因为我对 Docker 比较熟悉,所以采用 docker 做为容器,默认为 containerd
curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh
Server 安装
curl -sfL https://get.k3s.io | sh -
curl -sfL https://get.k3s.io | sh -s - --docker
# 读出装好以后的 token 备用,其它 Agent 机器才能加入集群
cat /var/lib/rancher/k3s/server/node-token
--docker
表示 用 docker 代替 containerd
添加 Node
获取上一步的 Token 以后替换以直命令,并在 Node 机器上执行
curl -sfL https://get.k3s.io | K3S_URL=https://myserver:6443 K3S_TOKEN=${token} sh -
curl -sfL https://get.k3s.io | K3S_URL=https://myserver:6443 K3S_TOKEN=${token} sh -s - --docker
组建 Server 集群
如果有多台 Server ,可以通过以下命令组建集群
K3S_TOKEN=mynodetoken k3s server --server https://myserver:6443
修改环境变量
echo 'PATH=$PATH:/usr/local/bin'>>/etc/profile
检查集群状态
kubectl config get-clusters
kubectl cluster-info
kubectl get nodes
kubectl get namespaces
kubectl get endpoints -n kube-system
kubectl get pods -n kube-system
实例管理
crictl ps
docker ps
管理界面安装及启动
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|.*/||')
k3s kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/${VERSION_KUBE_DASHBOARD}/aio/deploy/recommended.yaml
cat << EOF >dashboard.admin-user.yml
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kubernetes-dashboard
EOF
cat << EOF >dashboard.admin-user-role.yml
apiVersion: 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
EOF
k3s kubectl create -f dashboard.admin-user.yml -f dashboard.admin-user-role.yml
k3s kubectl -n kubernetes-dashboard describe secret admin-user-token | grep ^token
k3s kubectl proxy --accept-hosts='.*' --address='0.0.0.0'
查看 token
kubectl -n kube-system describe $(kubectl -n kube-system get secret -n kube-system -o name | grep namespace) | grep token