Files
gateway/.gitea/workflows/deploy.yml
张斌 2850fc7cd8
All checks were successful
全局K3s部署 / deploy (push) Successful in 5s
1
2026-05-22 14:34:13 +08:00

34 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
# 写入组织配置的SSH私钥
echo "${{ secrets.K3S_SSH_KEY }}" > k3s.pem
chmod 600 k3s.pem
# 调试:验证私钥是否正确写入
echo "私钥文件权限:"
ls -l k3s.pem
echo "私钥头部仅前5行"
head -5 k3s.pem
# 测试连接会输出服务器主机名和kubectl版本
ssh -i k3s.pem -o StrictHostKeyChecking=no -o ConnectTimeout=10 root@${K3S_HOST} "hostname && kubectl version --client"
# 正式执行部署命令
ssh -i k3s.pem -o StrictHostKeyChecking=no root@${K3S_HOST} << CMD
kubectl apply -f /k8s/deploy.yaml
kubectl rollout restart deployment ${APP_NAME}
CMD