K3S
部署K3S 是轻量级的 Kubernetes。易于安装,仅需要 Kubernetes 内存的一半,所有组件都在一个小于 100 MB 的二进制文件中。
它适用于:
本文介绍了高可用(HA)K3s 服务器集群的架构。
Spec | 最低 | 推荐 |
---|---|---|
CPU | 1核 | 2核 |
RAM | 512MB | 1GB |
Software | Version |
---|---|
Operating System | CentOS 7.9-x86_64(DVD) |
containerd | v1.7.2 |
k3s | v1.26.5+k3s1 |
Role | IP |
---|---|
k3s-main | 192.168.81.131 |
k3s-node1 | 192.168.81.132 |
# 配置yum源
yum install -y yum-utils
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 关闭防火墙
sudo systemctl stop firewalld
sudo systemctl disable firewalld
# 关闭SeLinux
sudo setenforce 0
sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
# 设置主机名
hostnamectl set-hostname <hostname>
# 修改hosts文件
cat >> /etc/hosts << EOF
192.168.81.131 k3s-main
192.168.81.132 k3s-node1
EOF
# 修改resolv.conf,解决域名解析失败的问题
cat >> /etc/resolv.conf << EOF
nameserver 8.8.8.8
nameserver 114.114.114.114
EOF
# 同步时间
yum install ntpdate -y
ntpdate time.windows.com
yum install containerd -y
systemctl start containerd && systemctl enable containerd
curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn sh -
kubectl get nodes
k3s check-config
vim /etc/default/grub
# 原始值
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"
# 修改后
GRUB_CMDLINE_LINUX="user_namespace.enable=1 crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"
cat /var/lib/rancher/k3s/server/node-token
curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn K3S_URL=https://myserver:6443 K3S_TOKEN=mynodetoken sh -
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 create -f https://raw.githubusercontent.com/kubernetes/dashboard/${VERSION_KUBE_DASHBOARD}/aio/deploy/recommended.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kubernetes-dashboard
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
kubectl create -f dashboard.admin-user.yml -f dashboard.admin-user-role.yml
kubectl -n kubernetes-dashboard create token admin-user
kubectl proxy
curl http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
kubectl delete ns kubernetes-dashboard
kubectl delete clusterrolebinding kubernetes-dashboard
kubectl delete clusterrole kubernetes-dashboard
交友小贴士:
博主Github,Gitee同名账号,Follow 一下就可以一起愉快的玩耍了,更多精彩文章请持续关注。