Deploy From Git Repo
方案 1:为 ArgoCD 添加 SSH 密钥(推荐用于私有仓库)
1. 生成 SSH 密钥(如果还没有)
ssh-keygen -t ed25519 -C "argocd@your-cluster" -f ~/.ssh/argocd_key -N ""2. 将公钥添加到 GitHub
复制公钥内容
cat ~/.ssh/argocd_key.pub然后在 GitHub 仓库设置 -> Deploy keys 中添加
3. 将私钥添加到 ArgoCD
argocd repo add git@github.com:AaronYang0628/Euclid-Image-Cutout-Service.git \
--ssh-private-key-path ~/.ssh/argocd_key方案 2:使用 HTTPS + Token(更简单)
1. 在 GitHub 生成 Personal Access Token
Settings -> Developer settings -> Personal access tokens -> Generate new token (需要 ‘repo’ 权限)
2. 使用 HTTPS URL 添加仓库
argocd repo add https://github.com/AaronYang0628/Euclid-Image-Cutout-Service.git \
--username AaronYang0628 \
--password <your-github-token>方案 3:公开仓库(如果可以)
如果这个仓库可以公开,直接使用 HTTPS URL 无需认证:
argocd repo add https://github.com/AaronYang0628/Euclid-Image-Cutout-Service.git验证连接
添加仓库后,验证连接:
argocd repo list创建 Application
连接成功后,创建 ArgoCD Application:
argocd app create euclid-cutout \
--repo https://github.com/AaronYang0628/Euclid-Image-Cutout-Service.git \
--path k8s \
--dest-server https://kubernetes.default.svc \
--dest-namespace default Sync
When your k8s resource files located in `mainfests` folder, you can use the following command to deploy your app.
you only need to set `spec.source.path: mainfests`
- sample-repo
- content
- src
- mainfests
- deploy.yaml
- svc.yaml
- …
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: hugo-blog
spec:
project: default
source:
repoURL: 'git@github.com:<$github_username>/sample-repo.git'
targetRevision: main
path: mainfests
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
- ApplyOutOfSyncOnly=true
destination:
server: https://kubernetes.default.svc
namespace: applicationNot only you need files in `mainfests` folder, but also need files in root folder.
适用于:待部署的应用不只需要k8s资源,还需要源代码中的一些数据或者文件时
you have to create an extra file `kustomization.yaml`, and set `spec.source.path: .`
- sample-repo
- kustomization.yaml
- content
- src
- mainfests
- deploy.yaml
- svc.yaml
- …
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: hugo-blog
spec:
project: default
source:
repoURL: 'git@github.com:<$github_username>/sample-repo.git'
targetRevision: main
path: .
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
- ApplyOutOfSyncOnly=true
destination:
server: https://kubernetes.default.svc
namespace: applicationresources:
- manifests/pvc.yaml
- manifests/job.yaml
- manifests/deployment.yaml
- ...