Compare commits
21 Commits
Author | SHA1 | Date | |
---|---|---|---|
7beb4ca57f | |||
6f8cd5cc22 | |||
ea7ca60477 | |||
9af73a40ca | |||
22848f01e7 | |||
a031b90da9 | |||
2cdf1bf16d | |||
3c6ce06ce6 | |||
bffce05b53 | |||
97d3881bee | |||
6f59ff50e3 | |||
ea93cbd1b9 | |||
3db6138e91 | |||
1e3d6cfcaa | |||
919511263f | |||
b7e78c1b43 | |||
c246adc39e | |||
9876eeb491 | |||
f3e2fe88d5 | |||
a593dea13c | |||
6535e48260 |
@ -14,9 +14,9 @@ jobs:
|
|||||||
- name: Log in to Docker Hub
|
- name: Log in to Docker Hub
|
||||||
uses: https://git.martin98.com/actions/login-action.git@v3
|
uses: https://git.martin98.com/actions/login-action.git@v3
|
||||||
with:
|
with:
|
||||||
registry: ${{ vars.DOCKER_HUB }}
|
registry: ${{ vars.GIT_IMAGE_URL }}
|
||||||
username: ${{ vars.DOCKER_USERNAME }}
|
username: ${{ vars.GIT_IMAGE_USERNAME }}
|
||||||
password: ${{ vars.DOCKER_PASSWORD }}
|
password: ${{ vars.GIT_IMAGE_PASSWORD }}
|
||||||
|
|
||||||
- name: Build and push
|
- name: Build and push
|
||||||
uses: https://git.martin98.com/actions/build-push-action.git@v4
|
uses: https://git.martin98.com/actions/build-push-action.git@v4
|
||||||
@ -25,5 +25,5 @@ jobs:
|
|||||||
platforms: linux/amd64
|
platforms: linux/amd64
|
||||||
push: true
|
push: true
|
||||||
tags: |
|
tags: |
|
||||||
docker.martin98.com/martin_farm/init:latest
|
git.martin98.com/martinfarm/init:latest
|
||||||
docker.martin98.com/martin_farm/init:${{ github.sha }}
|
git.martin98.com/martinfarm/init:${{ github.sha }}
|
@ -1,3 +1,9 @@
|
|||||||
|
## k3s
|
||||||
|
> https://docs.k3s.io/zh/quick-start
|
||||||
|
```bash
|
||||||
|
curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn sh -
|
||||||
|
```
|
||||||
|
|
||||||
## k8s 快速部署
|
## k8s 快速部署
|
||||||
```bash
|
```bash
|
||||||
# 网段配置
|
# 网段配置
|
||||||
|
@ -6,15 +6,18 @@ x-app-config: &app-config
|
|||||||
- ./:/app
|
- ./:/app
|
||||||
|
|
||||||
services:
|
services:
|
||||||
|
alpine:
|
||||||
|
<<: *app-config
|
||||||
|
image: alpine:latest
|
||||||
|
|
||||||
debian:
|
debian:
|
||||||
<<: *app-config
|
<<: *app-config
|
||||||
image: docker.martin98.com/library/debian:latest
|
image: debian:latest
|
||||||
|
|
||||||
ubuntu:
|
ubuntu:
|
||||||
<<: *app-config
|
<<: *app-config
|
||||||
image: docker.martin98.com/library/ubuntu:latest
|
image: ubuntu:latest
|
||||||
|
|
||||||
ubuntu-2204:
|
ubuntu-2204:
|
||||||
<<: *app-config
|
<<: *app-config
|
||||||
image: docker.martin98.com/library/ubuntu:22.04
|
image: ubuntu:22.04
|
@ -93,7 +93,7 @@ if [ -z "$CHANNEL" ]; then
|
|||||||
CHANNEL=$DEFAULT_CHANNEL_VALUE
|
CHANNEL=$DEFAULT_CHANNEL_VALUE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
DEFAULT_DOWNLOAD_URL="https://mirrors.martin98.com/repository/docker-ce/"
|
DEFAULT_DOWNLOAD_URL="https://reg.martin98.com/repository/docker-ce/"
|
||||||
#DEFAULT_DOWNLOAD_URL="https://download.docker.com"
|
#DEFAULT_DOWNLOAD_URL="https://download.docker.com"
|
||||||
if [ -z "$DOWNLOAD_URL" ]; then
|
if [ -z "$DOWNLOAD_URL" ]; then
|
||||||
DOWNLOAD_URL=$DEFAULT_DOWNLOAD_URL
|
DOWNLOAD_URL=$DEFAULT_DOWNLOAD_URL
|
||||||
|
85
init-apt.sh
85
init-apt.sh
@ -1,36 +1,60 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
APT_OPTIONS="-o Acquire::https::mirrors.martin98.com::Verify-Peer=false -o Acquire::https::mirrors.martin98.com::Verify-Host=false"
|
# Alpine 相关处理
|
||||||
lsb_dist=$(cat /etc/*release | grep ^ID= | cut -d= -f2) # ubuntu or debian?
|
handle_alpine() {
|
||||||
release=$(cat /etc/*release | grep VERSION_CODENAME | cut -d= -f2) # ubuntu(jammy oracular) debian(bookworm)....
|
echo "检测到 Alpine,切换 apk 源..."
|
||||||
components=$([ "${lsb_dist=}" = "debian" ] && echo "main contrib non-free non-free-firmware" || ([ "${lsb_dist=}" = "ubuntu" ] && echo "main restricted universe multiverse"))
|
sed -i 's#https\?://dl-cdn.alpinelinux.org/alpine#https://reg.martin98.com/repository/alpine#g' /etc/apk/repositories
|
||||||
|
|
||||||
# 删除 DEB822 格式
|
echo "安装 openntpd 和 vim..."
|
||||||
if [ -f /etc/apt/sources.list.d/${lsb_dist}.sources ]; then
|
apk update
|
||||||
|
apk add --no-cache openntpd vim
|
||||||
|
|
||||||
|
# 启动并设置 openntpd 开机自启
|
||||||
|
rc-service openntpd restart
|
||||||
|
rc-update add openntpd default
|
||||||
|
|
||||||
|
# 配置 vim 粘贴
|
||||||
|
if ! grep -q "set pastetoggle=" ~/.vimrc; then
|
||||||
|
echo "set pastetoggle=" >> ~/.vimrc
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Debian/Ubuntu 相关处理
|
||||||
|
handle_debian_ubuntu() {
|
||||||
|
APT_OPTIONS="-o Acquire::https::reg.martin98.com::Verify-Peer=false -o Acquire::https::reg.martin98.com::Verify-Host=false"
|
||||||
|
lsb_dist=$(cat /etc/*release | grep ^ID= | cut -d= -f2) # ubuntu or debian?
|
||||||
|
release=$(cat /etc/*release | grep VERSION_CODENAME | cut -d= -f2) # ubuntu(jammy oracular) debian(bookworm)....
|
||||||
|
components=$([ "${lsb_dist=}" = "debian" ] && echo "main contrib non-free non-free-firmware" || ([ "${lsb_dist=}" = "ubuntu" ] && echo "main restricted universe multiverse"))
|
||||||
|
|
||||||
|
# 删除 DEB822 格式
|
||||||
|
if [ -f /etc/apt/sources.list.d/${lsb_dist}.sources ]; then
|
||||||
rm /etc/apt/sources.list.d/${lsb_dist}.sources
|
rm /etc/apt/sources.list.d/${lsb_dist}.sources
|
||||||
fi
|
fi
|
||||||
# 配置镜像源
|
# 配置镜像源
|
||||||
cat <<EOF > /etc/apt/sources.list
|
cat <<EOF > /etc/apt/sources.list
|
||||||
deb https://mirrors.martin98.com/repository/$lsb_dist $release $components
|
deb https://reg.martin98.com/repository/$lsb_dist $release $components
|
||||||
deb https://mirrors.martin98.com/repository/$lsb_dist $release-updates $components
|
deb https://reg.martin98.com/repository/$lsb_dist $release-updates $components
|
||||||
deb https://mirrors.martin98.com/repository/$lsb_dist $release-backports $components
|
deb https://reg.martin98.com/repository/$lsb_dist $release-backports $components
|
||||||
deb https://mirrors.martin98.com/repository/$lsb_dist $release-security $components
|
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
for RELEASE in "$@"; do
|
for RELEASE in "$@"; do
|
||||||
echo "deb https://mirrors.martin98.com/repository/$lsb_dist $RELEASE $components" >> /etc/apt/sources.list
|
echo "deb https://reg.martin98.com/repository/$lsb_dist $RELEASE $components" >> /etc/apt/sources.list
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# 关闭交互式弹窗
|
||||||
|
echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
|
||||||
|
|
||||||
# 关闭交互式弹窗
|
apt update $APT_OPTIONS && apt install $APT_OPTIONS -y ca-certificates curl && update-ca-certificates
|
||||||
echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
|
apt update && apt upgrade -y
|
||||||
|
|
||||||
apt update $APT_OPTIONS && apt install $APT_OPTIONS -y ca-certificates curl && update-ca-certificates
|
# 检查并安装 vim
|
||||||
apt update && apt upgrade -y
|
if ! command -v vim >/dev/null 2>&1; then
|
||||||
|
apt install $APT_OPTIONS -y vim
|
||||||
|
fi
|
||||||
|
|
||||||
# NTP
|
# NTP
|
||||||
# 启用阿里云 ntp
|
# 启用阿里云 ntp
|
||||||
if pidof systemd >/dev/null 2>&1; then
|
if pidof systemd >/dev/null 2>&1; then
|
||||||
apt install chrony -y
|
apt install chrony -y
|
||||||
cat > /etc/chrony.conf <<EOF
|
cat > /etc/chrony.conf <<EOF
|
||||||
server ntp4.aliyun.com minpoll 4 maxpoll 10 iburst
|
server ntp4.aliyun.com minpoll 4 maxpoll 10 iburst
|
||||||
@ -40,13 +64,20 @@ allow 127.0.0.1
|
|||||||
EOF
|
EOF
|
||||||
timedatectl set-timezone Asia/Shanghai
|
timedatectl set-timezone Asia/Shanghai
|
||||||
systemctl restart chrony && systemctl enable chrony
|
systemctl restart chrony && systemctl enable chrony
|
||||||
else
|
else
|
||||||
echo "systemctl 不存在,跳过 chrony 的重启"
|
echo "systemctl 不存在,跳过 chrony 的重启"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# fix vim 粘贴
|
# fix vim 粘贴
|
||||||
if pidof vim >/dev/null 2>&1; then
|
|
||||||
if ! grep -q "set pastetoggle=" ~/.vimrc; then
|
if ! grep -q "set pastetoggle=" ~/.vimrc; then
|
||||||
echo "set pastetoggle=" >> ~/.vimrc
|
echo "set pastetoggle=" >> ~/.vimrc
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# 主流程
|
||||||
|
if grep -qi 'alpine' /etc/*release; then
|
||||||
|
handle_alpine
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
handle_debian_ubuntu "$@"
|
||||||
fi
|
fi
|
@ -22,23 +22,22 @@ elif command_exists docker; then
|
|||||||
else
|
else
|
||||||
# docker
|
# docker
|
||||||
if [ ! -f /usr/share/keyrings/docker-archive-keyring.gpg ]; then
|
if [ ! -f /usr/share/keyrings/docker-archive-keyring.gpg ]; then
|
||||||
curl -fsSL https://mirrors.martin98.com/repository/docker-ce/linux/$lsb_dist/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
|
curl -fsSL https://reg.martin98.com/repository/docker-ce/linux/$lsb_dist/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
|
||||||
fi
|
fi
|
||||||
echo "deb [signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.martin98.com/repository/docker-ce/linux/$lsb_dist $release stable" > /etc/apt/sources.list.d/docker.list
|
echo "deb [signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://reg.martin98.com/repository/docker-ce/linux/$lsb_dist $release stable" > /etc/apt/sources.list.d/docker.list
|
||||||
|
|
||||||
curl -sSL https://git.martin98.com/MartinFarm/init/raw/branch/main/docker-install.sh | sh
|
curl -sSL https://git.martin98.com/MartinFarm/init/raw/branch/main/docker-install.sh | sh
|
||||||
cat > /etc/docker/daemon.json <<EOF
|
fi
|
||||||
|
|
||||||
|
cat > /etc/docker/daemon.json <<EOF
|
||||||
{
|
{
|
||||||
"registry-mirrors": [
|
"registry-mirrors": [
|
||||||
"https://docker.martin98.com",
|
"https://docker.martin98.com"
|
||||||
"https://registry-docker.martin98.com",
|
|
||||||
"https://registry-dockerhub.hk.martin98.com"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
if pidof systemd >/dev/null 2>&1; then
|
if pidof systemd >/dev/null 2>&1; then
|
||||||
systemctl restart docker
|
systemctl restart docker
|
||||||
else
|
else
|
||||||
echo "systemctl 不存在,跳过 docker 重启。"
|
echo "systemctl 不存在,跳过 docker 重启。"
|
||||||
fi
|
|
||||||
fi
|
fi
|
@ -5,7 +5,7 @@ if command -v git > /dev/null 2>&1; then
|
|||||||
echo "git 已安装,正在配置镜像源..."
|
echo "git 已安装,正在配置镜像源..."
|
||||||
# 曾经设置过的强制取消
|
# 曾经设置过的强制取消
|
||||||
git config --global --unset url."https://git-proxy.hk.martin98.com/".insteadOf
|
git config --global --unset url."https://git-proxy.hk.martin98.com/".insteadOf
|
||||||
git config --global url."https://git-proxy.hk.martin98.com/https://github.com/".insteadOf "https://github.com/"
|
git config --global url."https://git.mirrors.martin98.com/https://github.com/".insteadOf "https://github.com/"
|
||||||
echo "镜像源配置完成。"
|
echo "镜像源配置完成。"
|
||||||
else
|
else
|
||||||
echo "git 不存在,跳过..."
|
echo "git 不存在,跳过..."
|
||||||
|
107
init-k3s.sh
Normal file
107
init-k3s.sh
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
curl -sSL https://git.martin98.com/MartinFarm/init/raw/branch/main/init-apt.sh | bash
|
||||||
|
|
||||||
|
current_ip=$(hostname -I | awk '{print $1}')
|
||||||
|
|
||||||
|
# 镜像加速
|
||||||
|
mkdir /etc/rancher/k3s -p
|
||||||
|
|
||||||
|
cat <<EOF > /etc/rancher/k3s/registries.yaml
|
||||||
|
mirrors:
|
||||||
|
docker.io:
|
||||||
|
endpoint:
|
||||||
|
- https://docker.martin98.com
|
||||||
|
registry-1.docker.io:
|
||||||
|
endpoint:
|
||||||
|
- https://docker.martin98.com
|
||||||
|
registry.k8s.io:
|
||||||
|
endpoint:
|
||||||
|
- https://docker.martin98.com
|
||||||
|
k8s.gcr.io:
|
||||||
|
endpoint:
|
||||||
|
- https://docker.martin98.com
|
||||||
|
gcr.io:
|
||||||
|
endpoint:
|
||||||
|
- https://docker.martin98.com
|
||||||
|
ghcr.io:
|
||||||
|
endpoint:
|
||||||
|
- https://docker.martin98.com
|
||||||
|
quay.io:
|
||||||
|
endpoint:
|
||||||
|
- https://docker.martin98.com
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# systemctl restart k3s
|
||||||
|
|
||||||
|
# 安装 keepalived
|
||||||
|
apt install -y keepalived
|
||||||
|
|
||||||
|
# 检查是否为 Master-01
|
||||||
|
if [ "$current_ip" == "$master" ]; then
|
||||||
|
state=MASTER
|
||||||
|
priority=100
|
||||||
|
else
|
||||||
|
state=BACKUP
|
||||||
|
priority=100
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 初始化 VIP
|
||||||
|
mkdir /etc/keepalived
|
||||||
|
cat <<EOF | sudo tee /etc/keepalived/keepalived.conf
|
||||||
|
vrrp_instance VI_1 {
|
||||||
|
state $state
|
||||||
|
interface eth0
|
||||||
|
virtual_router_id 51
|
||||||
|
priority $priority
|
||||||
|
advert_int 1
|
||||||
|
virtual_ipaddress {
|
||||||
|
$vip
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sudo systemctl restart keepalived
|
||||||
|
systemctl status keepalived &
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 检查是否为 Master-01
|
||||||
|
if [ "$current_ip" == "$master" ]; then
|
||||||
|
# 开始部署
|
||||||
|
curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn sh -s - server \
|
||||||
|
--cluster-init \
|
||||||
|
--cluster-cidr $pod_subnet \
|
||||||
|
--service-cidr $service_subnet \
|
||||||
|
--node-external-ip=$vip_ip \
|
||||||
|
|
||||||
|
|
||||||
|
TOKEN=$(cat /var/lib/rancher/k3s/server/node-token)
|
||||||
|
cat <<EOF
|
||||||
|
------------------------------------------------------------------------------------
|
||||||
|
初始化 master VIP[$state] $current_ip 成功
|
||||||
|
|
||||||
|
export pod_subnet=$pod_subnet
|
||||||
|
export service_subnet=$service_subnet
|
||||||
|
export vip_ip=$vip_ip
|
||||||
|
export vip=$vip_ip/16
|
||||||
|
export master=$master
|
||||||
|
export TOKEN=$TOKEN
|
||||||
|
curl -sSL https://git.martin98.com/MartinFarm/init/raw/branch/main/init-k3s.sh | bash
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------------
|
||||||
|
EOF
|
||||||
|
|
||||||
|
else
|
||||||
|
curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn sh -s - server \
|
||||||
|
--cluster-cidr $pod_subnet \
|
||||||
|
--service-cidr $service_subnet \
|
||||||
|
--node-external-ip=$vip_ip \
|
||||||
|
--token $TOKEN \
|
||||||
|
--server https://$master:6443
|
||||||
|
watch kubectl get nodes
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user