1、官网K3s
#一条命令搞定
curl -sfL https://get.k3s.io | sh -
# Check for Ready node, takes ~30 seconds
k3s kubectl get node
由于访问github慢,可以使用以下方式
1、etcd
#一条命令搞定(etcd)
[root@hecs-99591 ~]# time curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | \
> INSTALL_K3S_MIRROR=cn \
> sh -s -
2、 mysql
#一条命令搞定(mysql)
curl -sfL https://rancher-mirror.oss-cn-beijing.aliyuncs.com/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn sh -s - server --datastore-endpoint="mysql://demo:demo123@tcp(mysql.demo.com:3306)/demodb"
参数解释:
–docker:使用docker,默认是containerd。
–datastore-endpoint 指定外部数据库(格式: mysql://数据库账号:数据库密码@tcp(数据库连接地址:数据库端口)/数据库名称)
2、在K3S集群Server节点服务器查看token令牌凭证
如上一步的机器就是Server节点,上面服务器中执行如下:
cat /var/lib/rancher/k3s/server/node-token
3、向K3S集群中添加新的节点
1.添加Server节点(如不需要添加Server节点可忽略)
这里添加Server节点跟第一个节点安装一样, 需要多加了一个 --token=token令牌凭证 , 这里是上面一步查到的token令牌凭证
curl -sfL https://rancher-mirror.oss-cn-beijing.aliyuncs.com/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn sh -s - server --token=mytoken --datastore-endpoint="mysql://demo:demo123@tcp(mysql.demo.com:3306)/demodb"
2.添加Agent节点(如不需要添加Agent节点可忽略)
这里添加Agent节点需要指定Server节点地址 跟 token令牌凭证
curl -sfL https://rancher-mirror.oss-cn-beijing.aliyuncs.com/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn K3S_URL=https://192.168.4.160:6443 K3S_TOKEN=mytoken sh -
K3S_URL=https://192.168.4.160:6443 表示 K3S集群 server节点的地址, 可以是任意一个主节点地址,如果配置了主节点的负载均衡地址的话,这可以填那个统一的域名地址
K3S_TOKEN=mytoken 表示token令牌凭证,在每个Server节点中都有一份,查看获取(这里是上面一步查到的token令牌凭证)
4、将 kubeconfig 文件拷贝至默认的目录下
K3s 默认的配置文件路径,Helm无法识别,将 /etc/rancher/k3s/k3s.yaml 软连接到 ~/.kube/config,供 helm 使用
mkdir ~/.kube && ln -s /etc/rancher/k3s/k3s.yaml ~/.kube/config
5、检查是否安装成功
自此k3s安装完成
6、kubectl 命令自动补全
#安装bash-completion
yum install -y bash-completion
source /usr/share/bash-completion/bash_completion
#应用kubectl的completion到系统环境
source <(kubectl completion bash)
echo "source <(kubectl completion bash)" >> ~/.bashrc
7、检查资源文件是否正常
#执行 kubectl apply --dry-run=client -f XXXX.yaml
[root@hecs-99591 nacos]# kubectl apply --dry-run=client -f nacos-deployment.yaml
deployment.apps/nacos-deployment configured (dry run)
K3S单节点及高可用安装(rockylinux8.6+containerd)_k3s增加节点_w23939296的博客-CSDN博客