update
This commit is contained in:
parent
29a610d1ad
commit
ab18b6d55c
@ -1,7 +1,7 @@
|
||||
---
|
||||
title: "CentOS7 安装 K3S"
|
||||
title: "RockyLinux 8.5 安装 K3S"
|
||||
date: 2020-09-25T14:21:00+08:00
|
||||
lastmod: 2020-09-25T14:21:00+08:00
|
||||
lastmod: 2022-08-10T15:40:00+08:00
|
||||
keywords: []
|
||||
tags: ["rancher", "k3s"]
|
||||
categories: ["container"]
|
||||
@ -9,13 +9,13 @@ categories: ["container"]
|
||||
|
||||
## 环境
|
||||
|
||||
角色 | 主机名 | 操作系统 | 软件
|
||||
---- | ---- | ---- | ----
|
||||
数据库 | - | - | docker-ce 19.03
|
||||
k3s server | k3s-server0 | CentOS7.8 | docker-ce 19.03, k3s v1.18.9
|
||||
k3s server | k3s-server1 | CentOS7.8 | docker-ce 19.03, k3s v1.18.9
|
||||
k3s agent | k3s-agent0 | CentOS7.8 | docker-ce 19.03, k3s v1.18.9
|
||||
k3s agent | k3s-agent1 | CentOS7.8 | docker-ce 19.03, k3s v1.18.9
|
||||
角色 | 主机名 | 操作系统 | 软件
|
||||
---- | ---- | ---- | ----
|
||||
数据库 | - | - | docker 20.10
|
||||
k3s server | k3s-server0 | RockyLinux 8.5 | docker 20.10, k3s v1.23.9
|
||||
k3s server | k3s-server1 | RockyLinux 8.5 | docker 20.10, k3s v1.23.9
|
||||
k3s agent | k3s-agent0 | RockyLinux 8.5 | docker 20.10, k3s v1.23.9
|
||||
k3s agent | k3s-agent1 | RockyLinux 8.5 | docker 20.10, k3s v1.23.9
|
||||
|
||||
- **全部服务器关闭 firewalld、selinux 和 swap,设置时间同步**
|
||||
- **全部 k3s 服务器(除了数据库)必须设置唯一主机名**
|
||||
@ -25,32 +25,29 @@ k3s agent | k3s-agent1 | CentOS7.8 | docker-ce 19.03, k3s v1.18.9
|
||||
- 启动 docker 容器
|
||||
```bash
|
||||
docker run -d \
|
||||
--name mariadb \
|
||||
--name mysql \
|
||||
-p 3306:3306 \
|
||||
-v /data/mariadb/binlog:/var/lib/mysql-bin \
|
||||
-v /data/mariadb/db:/var/lib/mysql \
|
||||
-v /data/mariadb/log:/var/log/mysql \
|
||||
harbor.colben.cn/general/alpine-mariadb
|
||||
harbor.colben.cn/general/mysql:8
|
||||
```
|
||||
|
||||
- 创建 k3s 数据库
|
||||
```bash
|
||||
docker exec mariadb mysql -e "
|
||||
docker exec mysql mysql -e "
|
||||
CREATE DATABASE k3s DEFAULT CHARSET UTF8MB4;
|
||||
CREATE USER k3s@'%' IDENTIFIED BY 'Password_1234';
|
||||
GRANT ALL ON k3s.* TO k3s@'%';
|
||||
FLUSH PRIVILEGES;
|
||||
"
|
||||
```
|
||||
|
||||
- 生产环境建议配置 mysql 主从高可用,参考[MariaDB 主从复制](/post/mariadb-replication/)
|
||||
|
||||
## 安装 k3s server
|
||||
- 在每台 k3s server 服务器上执行如下操作
|
||||
- 下载并安装 k3s
|
||||
```bash
|
||||
cd /usr/local/bin/
|
||||
curl -LO https://github.com/rancher/k3s/releases/download/v1.18.9%2Bk3s1/k3s
|
||||
curl -LO https://github.com/k3s-io/k3s/releases/download/v1.23.9%2Bk3s1/k3s
|
||||
chmod 0755 k3s
|
||||
ln -s k3s kubectl
|
||||
```
|
||||
@ -61,6 +58,7 @@ k3s agent | k3s-agent1 | CentOS7.8 | docker-ce 19.03, k3s v1.18.9
|
||||
Description=Lightweight Kubernetes
|
||||
Documentation=https://k3s.io
|
||||
Wants=network-online.target
|
||||
After=network-online.target
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@ -82,9 +80,14 @@ k3s agent | k3s-agent1 | CentOS7.8 | docker-ce 19.03, k3s v1.18.9
|
||||
ExecStart=/usr/local/bin/k3s \
|
||||
server \
|
||||
--docker \
|
||||
--datastore-endpoint 'mysql://k3s:Password_1234@tcp({mysql 地址}:{mysql 端口})/k3s' \
|
||||
--token "123456" \
|
||||
--bind-address "0.0.0.0" \
|
||||
--https-listen-port "6443" \
|
||||
--cluster-cidr "10.42.0.0/16" \
|
||||
--service-cidr "10.43.0.0/16" \
|
||||
--pause-image 'harbor.colben.cn/k3s/pause:3.6' \
|
||||
--disable 'coredns,servicelb,traefik,local-storage,metrics-server' \
|
||||
--pause-image 'harbor.colben.cn/k3s/pause:3.2'
|
||||
--datastore-endpoint 'mysql://k3s:Password_1234@tcp({mysql 地址}:{mysql 端口})/k3s'
|
||||
```
|
||||
|
||||
- 重载 systemd 系统服务,启动 k3s-server 服务
|
||||
@ -93,11 +96,6 @@ k3s agent | k3s-agent1 | CentOS7.8 | docker-ce 19.03, k3s v1.18.9
|
||||
systemctl start k3s-server
|
||||
```
|
||||
|
||||
- 获取 token 信息(同一集群内各 server 上该文件完全一样),该信息用于 agent 连接
|
||||
```bash
|
||||
cat /var/lib/rancher/k3s/server/token
|
||||
```
|
||||
|
||||
- 多个 k3s-server 服务可通过 keepalived 配置高可用,参考[keepalived 笔记](/post/keepalived/)
|
||||
|
||||
## 安装 k3s agent
|
||||
@ -105,7 +103,7 @@ k3s agent | k3s-agent1 | CentOS7.8 | docker-ce 19.03, k3s v1.18.9
|
||||
- 下载并安装 k3s
|
||||
```bash
|
||||
cd /usr/local/bin/
|
||||
curl -LO https://github.com/rancher/k3s/releases/download/v1.18.9%2Bk3s1/k3s
|
||||
curl -LO https://github.com/k3s-io/k3s/releases/download/v1.23.9%2Bk3s1/k3s
|
||||
chmod 0755 k3s
|
||||
```
|
||||
|
||||
@ -115,6 +113,7 @@ k3s agent | k3s-agent1 | CentOS7.8 | docker-ce 19.03, k3s v1.18.9
|
||||
Description=Lightweight Kubernetes
|
||||
Documentation=https://k3s.io
|
||||
Wants=network-online.target
|
||||
After=network-online.target
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@ -136,9 +135,9 @@ k3s agent | k3s-agent1 | CentOS7.8 | docker-ce 19.03, k3s v1.18.9
|
||||
ExecStart=/usr/local/bin/k3s \
|
||||
agent \
|
||||
--docker \
|
||||
--token "123456" \
|
||||
--server 'https://{任一 server 地址或 server 高可用地址}:6443' \
|
||||
--pause-image 'harbor.boyachain.cn:20443/k3s/pause:3.2' \
|
||||
--token '{server token 信息}'
|
||||
--pause-image 'harbor.colben.cn/k3s/pause:3.6' \
|
||||
```
|
||||
|
||||
- 重载 systemd 系统服务,启动 k3s-agent 服务
|
||||
|
Loading…
x
Reference in New Issue
Block a user