Files
admin-ui/.gitea/workflows/deploy.yml
张斌 274b921b9a
Some checks failed
全局K3s部署 / deploy (push) Failing after 31s
dockerfile
2026-05-23 17:02:04 +08:00

33 lines
1.1 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: 全局K3s部署
on:
push:
branches: [master]
jobs:
deploy:
runs-on: ubuntu-latest
env:
# 从组织级Secrets读取不用在仓库重复配置
K3S_HOST: ${{ secrets.K3S_HOST }}
APP_NAME: ${{ gitea.repo_name }}
steps:
- name: 拉取代码
uses: actions/checkout@v4
- name: SSH部署K3s
run: |
mkdir -p ~/.ssh
echo "${{ secrets.K3S_PEM_KEY }}" > k3s.pem
chmod 600 k3s.pem
# 关键1上传当前仓库根目录的deploy.yaml到K3s服务器/tmp目录
# 若deploy.yaml在仓库k8s子目录改为 ./k8s/deploy.yaml
scp -i k3s.pem -o StrictHostKeyChecking=no ./deploy.yaml root@${K3S_HOST}:/tmp/
# 关键2执行kubectl指向临时文件补充命名空间避免找不到资源
ssh -i k3s.pem -o StrictHostKeyChecking=no root@${K3S_HOST} << CMD
kubectl apply -f /tmp/deploy.yaml
kubectl rollout restart deployment ${APP_NAME} -n default
# 可选:部署完成后删除临时文件,清理服务器
rm -f /tmp/deploy.yaml
CMD