ArgoCD CLI Sheet: GitOps Sync & Rollback

๐Ÿ’ก ArgoCD CLI Sheet: GitOps Sync & Rollback โ€” Executive Summary

Technical architectural analysis, practical configuration manifests, and deployment instructions for ArgoCD CLI Sheet: GitOps Sync & Rollback.

Installation
  • mac
bash
brew install argocd
  • amd64
bash
curl -sSL -o argocd-linux-amd64 https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-amd64
  sudo install -m 555 argocd-linux-amd64 /usr/local/bin/argocd
  rm argocd-linux-amd64
Exec
bash
# ๊ณ„์ • ๋กœ๊ทธ์ธ, ์•„๋ž˜์™€ ๊ฐ™์ด ์„ธ์…˜ ๋งŒ๋ฃŒ์‹œ์— ์žฌ๋กœ๊ทธ์ธ ํ•„์š”
# FATA[0003] rpc error: code = Unauthenticated desc = invalid session: Token is expired
argocd login 100.0.0.198:30088
Username: < ์ž…๋ ฅ >
Passwrod: < ์ž…๋ ฅ >

# ์•ฑ ์ƒ์„ฑ
argocd app create -f argocdapp-manifest.yaml
# ์œ„์™€ ๋™์ผ
kubectl apply -f argocdapp-manifest.yaml

# ์•ฑ ์‚ญ์ œ
argocd app delete $APPNAME -y

# ์•ฑ ๊ฐ•๋ ฅ ์ƒˆ๋กœ๊ณ ์นจ
argocd app get $APPNAME --hard-refresh

# ์•ฑ ๋™๊ธฐํ™”
argocd app sync $APPNAME -y
help
bash
argocd app delete --help
>>>
Delete an application

Usage:
  argocd app delete APPNAME [flags]

Flags:
      --cascade                     Perform a cascaded deletion of all application resources (default true)
  -h, --help                        help for delete
  -p, --propagation-policy string   Specify propagation policy for deletion of application's resources. One of: foreground|background (default "foreground")
  -y, --yes                         Turn off prompting to confirm cascaded deletion of application resources

Global Flags:
      --auth-token string               Authentication token
      --client-crt string               Client certificate file
      --client-crt-key string           Client certificate key file
      --config string                   Path to Argo CD config (default "/root/.argocd/config")
      --grpc-web                        Enables gRPC-web protocol. Useful if Argo CD server is behind proxy which does not support HTTP2.
      --grpc-web-root-path string       Enables gRPC-web protocol. Useful if Argo CD server is behind proxy which does not support HTTP2. Set web root.
  -H, --header strings                  Sets additional header to all requests made by Argo CD CLI. (Can be repeated multiple times to add multiple headers, also supports comma separated headers)
      --insecure                        Skip server certificate and domain verification
      --logformat string                Set the logging format. One of: text|json (default "text")
      --loglevel string                 Set the logging level. One of: debug|info|warn|error (default "info")
      --plaintext                       Disable TLS
      --port-forward                    Connect to a random argocd-server port using port forwarding
      --port-forward-namespace string   Namespace name which should be used for port forwarding
      --server string                   Argo CD server address
      --server-crt string               Server certificate file
<<<
Local Dashboard
bash
( sleep 1 && open http://localhost:8080/ ) & argocd admin dashboard -n argocd
Features
Easily read Argo-cd Apps using yq, jq
bash
cat cmp.yaml | yq -ojson | jq -r '{"app_name":.metadata.name, "path":.spec.source.path, "ENV": .spec.source.plugin.env[].value}'
Apply and install Helmfile Plugin
  • required
  • helm-git
bash
helm plugin install https://github.com/aslafy-z/helm-git --version 1.4.1f
  • age
bash
go install filippo.io/age/cmd/...@latest
  • Repo-server
  • ARGOCD_EXEC_TIMEOUT Undefined. Default: 90s
  • If the template takes a long time, the following error occurs
bash
Failed to load target state: failed to generate manifest for source 1 of 1: rpc error: code = DeadlineExceeded desc = context deadline exceeded
  • All sidecars in the following two resources
    • deploy/argocd-repo-server with plugin
    • sts/argocd-application-controller
bash
ARGOCD_EXEC_TIMEOUT=5m
  • Nginx-Ingress
  • Default timeout 60s
  • If the template takes a long time, the following error occurs
bash
{"level":"fatal","msg":"rpc error: code = Unknown desc = POST https://argocd.Enterprise Cloud.hanacloudia.com:443/application.ApplicationService/Get failed with status code 504","time":"2025-12-24T15:01:43+09:00"}
  • ing/argo-cd-argocd-server
bash
annotations:
        nginx.ingress.kubernetes.io/proxy-connect-timeout: "450"
        nginx.ingress.kubernetes.io/proxy-send-timeout: "450"
        nginx.ingress.kubernetes.io/proxy-read-timeout: "450"
  • ArgoCD Installation Sample
  • Without age key file
bash
#๊ฐ’ ํŒŒ์ผ์˜ ์ค‘์š”ํ•œ ์†์„ฑ์„ ์•”ํ˜ธํ™”ํ•˜๋Š” ๋ฐ ๊ฐœ์ธ ํ‚ค๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ์ง€ ์•Š๋‹ค๋ฉด ๋‹ค์Œ ๋ช…๋ น์„ ์‚ฌ์šฉํ•˜๋ฉด Argo CD์™€ Helmfile ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์„ค์น˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค... Helmfile .

    cat <<EOF | helmfile apply -f -
    repositories:
      - name: argo
        url: https://argoproj.github.io/argo-helm

    releases:
      - name: argocd
        namespace: argocd
        labels:
          app: argocd
        chart: argo/argo-cd
        version: ~7.8.23
        values:
        - repoServer:
            extraContainers:
            - name: plugin
              image: lucj/argocd-plugin-helmfile:latest
              command: ["/var/run/argocd/argocd-cmp-server"]
              securityContext:
                runAsNonRoot: true
                runAsUser: 999
              volumeMounts:
              - mountPath: /var/run/argocd
                name: var-files
              - mountPath: /home/argocd/cmp-server/plugins
                name: plugins
    EOF
  • Include age key file
bash
#๊ฐ’ ํŒŒ์ผ์˜ ๋ฏผ๊ฐํ•œ ์†์„ฑ์„ ์•”ํ˜ธํ™”ํ•˜๊ธฐ ์œ„ํ•ด ๊ฐœ์ธ ํ‚ค๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด Argo CD๋ฅผ ์„ค์น˜ํ•˜์„ธ์š”. ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด key.txt ํŒŒ์ผ์— age ํ‚ค๊ฐ€ ์ƒ์„ฑ๋˜๊ฑฐ๋‚˜ ๊ธฐ์กด ํ‚ค๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    cat <<EOF | helmfile apply -f -
    repositories:
      - name: argo
        url: https://argoproj.github.io/argo-helm

    releases:
      - name: argocd
        namespace: argocd
        labels:
          app: argocd
        chart: argo/argo-cd
        version: ~7.8.23
        values:
          - repoServer:
              volumes:
                - name: age
                  secret:
                    secretName: age
              extraContainers:
              - name: plugin
                image: lucj/argocd-plugin-helmfile:latest
                command: ["/var/run/argocd/argocd-cmp-server"]
                securityContext:
                  runAsNonRoot: true
                  runAsUser: 999
                env:
                - name: SOPS_AGE_KEY_FILE
                  value: /app/config/age/key.txt
                volumeMounts:
                - name: age
                  mountPath: "/app/config/age/"
                - mountPath: /var/run/argocd
                  name: var-files
                - mountPath: /home/argocd/cmp-server/plugins
                  name: plugins
        hooks:
        - events: ["presync"]
          showlogs: true
          command: "/bin/bash"
          args:
          - "-ec"
          - |
            # Create a sops / age secret key if none already exists
            if [[ -f ./key.txt ]]; then
              echo "age key.txt file already exists"
            else
              age-keygen > ./key.txt
            fi

            # Create secret to give Argo access to the age key
            kubectl create ns argocd || true
            kubectl -n argocd create secret generic age --from-file=key.txt=./key.txt || true
        - events: ["postuninstall"]
          showlogs: true
          command: "/bin/bash"
          args:
          - "-ec"
          - |
            # Remove secret created in the presync hook
            kubectl -n argocd delete secret age
    EOF
  • Application Sample
bash
#์ƒ˜ํ”Œ ๋งˆ์ดํฌ๋กœ์„œ๋น„์Šค ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ธ VotingApp์„ ์ •์˜ํ•˜๋Š” ๋‹ค์Œ Argo CD ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ฆฌ์†Œ์Šค๋ฅผ ์ƒ์„ฑํ•˜์„ธ์š”. Argo CD๋Š” ์ง€์ •๋œ (๋ฐ๋ชจ) ์ €์žฅ์†Œ์— ์žˆ๋Š” helmfile.yaml ํŒŒ์ผ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์ž๋™์œผ๋กœ ๋ฐฐํฌํ•ฉ๋‹ˆ๋‹ค.

  cat <<EOF | kubectl apply -f -
  apiVersion: argoproj.io/v1alpha1
  kind: Application
  metadata:
    name: votingapp
    namespace: argocd
    finalizers:
      - resources-finalizer.argocd.argoproj.io
  spec:
    project: default
    source:
      repoURL: https://gitlab.com/lucj/luc.run.git
      targetRevision: main
      path: misc/helmfiles/votingapp
      plugin: {}
    destination:
      server: https://kubernetes.default.svc
      namespace: vote
    syncPolicy:
      automated: {}
      syncOptions:
        - CreateNamespace=true
  EOF

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *