Skip to main content

Argo CD CRD


Repository

repository Secret에 모든 정보를 선언하는 방식과 repository Secret에 type, url만 선언하고 repo-creds Secret에 인증 정보만 선언하는 방식이 있습니다.

apiVersion: v1
kind: Secret
metadata:
name: github-<user>-<repository>-repo
namespace: argo-cd
labels:
argocd.argoproj.io/secret-type: repository
type: Opaque
stringData:
type: git
url: <ssh>:<user>/<repository>.git
# url: <url>/<user>/<repsitory>

# username: <username>
# password: <password>

# sshPrivateKey: <sshPrivateKey>
apiVersion: v1
kind: Secret
metadata:
name: github-<user>-creds
namespace: argo-cd
labels:
argocd.argoproj.io/secret-type: repo-creds
type: Opaque
stringData:
type: git
# <repsitory>는 선언하지 않습니다.
url: <ssh>:<user>
# url: <url>/<user>

# username: <username>
# password: <password>

# sshPrivateKey: <sshPrivateKey>

SSH

아래 명령어를 통해 SSH 키를 생성한 후, Public 키를 GitHub SSH 키에 추가합니다.

ssh-keygen -t ed25519 -N "" -C "[email protected]" -f argocd
apiVersion: v1
kind: Secret
metadata:
name: github-<user>-creds
namespace: argo-cd
labels:
argocd.argoproj.io/secret-type: repo-creds
type: Opaque
stringData:
type: git
url: [email protected]:<user>
sshPrivateKey: |
-----BEGIN OPENSSH PRIVATE KEY-----
...
-----END OPENSSH PRIVATE KEY-----

Cluster

External

원격으로 제어하고 싶은 클러스터에 아래와 같이 ServiceAccount를 생성해주세요. 예시는 Admin 권한이 부여된 상태이기 때문에 보안을 위해 권한을 제한해서 부여해주세요.

apiVersion: v1
kind: ServiceAccount
metadata:
name: argocd-manager
namespace: kube-system
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: argocd-manager-role
rules:
- apiGroups:
- "*"
resources:
- "*"
verbs:
- "*"
- nonResourceURLs:
- "*"
verbs:
- "*"
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: argocd-manager-role-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: argocd-manager-role
subjects:
- kind: ServiceAccount
name: argocd-manager
namespace: kube-system

서버 URL, 토큰, 인증서를 가져옵니다.

kubectl config view --minify -o jsonpath='{.clusters[0].cluster.server}'
kubectl -n kube-system get secret $(kubectl -n kube-system get sa/argocd-manager -o jsonpath="{.secrets[0].name}") -o go-template="{{.data.token | base64decode}}"
kubectl -n kube-system get secret $(kubectl -n kube-system get sa/argocd-manager -o jsonpath="{.secrets[0].name}") -o jsonpath="{.data['ca\.crt']}"

Argo CD가 설치된 클러스터에 아래와 같이 제어하고싶은 클러스터 정보를 추가해주세요.

apiVersion: v1
kind: Secret
metadata:
name: <cluster-name>-cluster
namespace: argo-cd
labels:
argocd.argoproj.io/secret-type: cluster
type: Opaque
stringData:
name: <cluster-name>
server: <url>
config: |
{
"bearerToken": "<token>",
"tlsClientConfig": {
"insecure": false,
"caData": "<base64 encoded certificate>"
}
}

AppProject

apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
name: <project>
namespace: argo-cd
finalizers:
# 하위에 속한 Application이 있으면 삭제 요청을 거부합니다.
- resources-finalizer.argocd.argoproj.io
spec:
description: ""
sourceRepos:
- [email protected]:<user>/<repository>.git
destinations:
- name: <cluster-name>
namespace: <namespace>
# 클러스터 스코프에서 허용되는 리소스 리스트입니다.
clusterResourceWhitelist:
- group: <group>
kind: <kind>
  • sourceRepos
    • 해당 AppProject에서 허용하는 리포지토리 목록입니다.
    • *을 사용하면 모든 리포지토리를 허용합니다.
  • destinations
    • 해당 AppProject에서 허용하는 클러스터 목록입니다.
    • name
      • 허용할 클러스터의 이름입니다.
      • *을 사용하면 모든 클러스터를 허용합니다.
    • namespace
      • 허용할 네임스페이스입니다.
      • *을 사용하면 모든 네임스페이스를 허용합니다.
    • server
      • 허용할 클러스터의 kube-apiserver의 URL입니다.
      • *을 사용하면 모든 클러스터를 허용합니다.
  • clusterResourceWhitelist
    • 해당 AppProject에서 허용하는 클러스터 스코프의 리소스 리스트입니다.
    • group
      • 허용할 리소스의 그룹입니다.
      • *을 사용하면 모든 그룹을 허용합니다.
    • kind
      • 허용할 리소스의 종류입니다.
      • *을 사용하면 모든 종류를 허용합니다.
  • namespaceResourceBlacklist
  • namespaceResourceWhitelist
  • roles

Application

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: <application>-<env>
namespace: argo-cd
labels:
"<example.com/project-env>": <env> # 웹 UI에서 필터링을 위해 사용할 수 있습니다.
finalizers:
# 삭제 요청 시 하위에 속한 리소스들을 삭제합니다.
- resources-finalizer.argocd.argoproj.io
spec:
project: <project>
source: {}
destination:
name: <cluster-name>
namespace: <namespace>
revisionHistoryLimit: <limit>
syncPolicy:
automated:
prune: true
selfHeal: true

Helm

argo-cd는 차트의 apiVersion이 v2더라도 v3를 사용합니다. v2를 사용하려면 .spec.source.helm.version을 v2라고 명시해야 합니다.

spec:
source:
repoURL: [email protected]:<user>/<repository>.git
path: <path>
targetRevision: <branch|tag>
helm:
valueFiles:
- <relative_path>/<values>.yaml

ApplicationSet

Reference