Manage Argo CD Repositories and Applications using Argo CD CLI

0
6315
Manage Argo CD Repositories and Applications using Argo CD CLI

In our last post we have seen how to install Argo CD CLI and demonstrated few Argo CD commands like clusters, context etc. In this post will see how to manage the Repositories and applications in Argo CD using CLI.

As we seen earlier, we can manage repo and apps via UI also, if you wish to manage all the resources via CLI, you can refer this and also this will help you to automate via any CI tool or some automation scripts.

Let’s start with repositories first, as we cannot add the application without repositories it is mandatory.

Prerequisites:

Video Demo

Repositories

argocd repo add

Add git repository connection parameters

# argocd repo add REPOURL [flags]

Examples

Add a Git repository via SSH using a private key for authentication, ignoring the server’s host key:

# argocd repo add git@git.example.com:repos/repo --insecure-ignore-host-key --ssh-private-key-path ~/id_rsa

Add a Git repository via SSH on a non-default port – need to use ssh:// style URLs here

# argocd repo add ssh://git@git.example.com:2222/repos/repo --ssh-private-key-path ~/id_rsa

Add a private Git repository via HTTPS using username/password and TLS client certificates:

# argocd repo add https://git.example.com/repos/repo --username git --password secret --tls-client-cert-path ~/mycert.crt --tls-client-cert-key-path ~/mycert.key

Add a private Git repository via HTTPS using username/password without verifying the server’s TLS certificate

# argocd repo add https://git.example.com/repos/repo --username git --password secret --insecure-skip-server-verification

Add a public Helm repository named ‘stable’ via HTTPS

# argocd repo add https://charts.helm.sh/stable --type helm --name stable

Add a private Helm repository named ‘stable’ via HTTPS

# argocd repo add https://charts.helm.sh/stable --type helm --name stable --username test --password test

Add a private Helm OCI-based repository named ‘stable’ via HTTPS

# argocd repo add helm-oci-registry.cn-zhangjiakou.cr.aliyuncs.com --type helm --name stable --enable-oci --username test --password test

Add a private Git repository on GitHub.com via GitHub App

# argocd repo add https://git.example.com/repos/repo --github-app-id 1 --github-app-installation-id 2 --github-app-private-key-path test.private-key.pem

Add a private Git repository on GitHub Enterprise via GitHub App

# argocd repo add https://ghe.example.com/repos/repo --github-app-id 1 --github-app-installation-id 2 --github-app-private-key-path test.private-key.pem --github-app-enterprise-base-url https://ghe.example.com/api/v3

argocd repo list

List configured repositories

# argocd repo list [flags]

Example:

# argocd repo list
# argocd repo list -o json
# argocd repo list -o yaml

argocd repo get

Get a configured repository by URL

# argocd repo get [flags]

Example

# argocd repo get https://github.com/foxutech/kubernetes.git
# argocd repo get https://github.com/foxutech/kubernetes.git -o json
# argocd repo get https://github.com/foxutech/kubernetes.git -o yaml

argocd repo rm

Remove repository credentials

# argocd repo rm REPO [flags]
Example: 
# argocd repo rm https://github.com/foxutech/kubernetes.git

Applications:

argocd app create

Create an application

# argocd app create APPNAME [flags]

Examples

Create a directory app

# argocd app create guestbook --repo https://github.com/argoproj/argocd-example-apps.git --path guestbook --dest-namespace default --dest-server https://kubernetes.default.svc --directory-recurse

Create a Jsonnet app

# argocd app create jsonnet-guestbook --repo https://github.com/argoproj/argocd-example-apps.git --path jsonnet-guestbook --dest-namespace default --dest-server https://kubernetes.default.svc --jsonnet-ext-str replicas=2

Helm app

# argocd app create helm-guestbook --repo https://github.com/argoproj/argocd-example-apps.git --path helm-guestbook --dest-namespace default --dest-server https://kubernetes.default.svc --helm-set replicaCount=2

Helm app from a Helm repo

# argocd app create nginx-ingress --repo https://charts.helm.sh/stable --helm-chart nginx-ingress --revision 1.24.3 --dest-namespace default --dest-server https://kubernetes.default.svc

Kustomize app

# argocd app create kustomize-guestbook --repo https://github.com/argoproj/argocd-example-apps.git --path kustomize-guestbook --dest-namespace default --dest-server https://kubernetes.default.svc --kustomize-image gcr.io/heptio-images/ks-guestbook-demo:0.1

app using a custom tool

# argocd app create kasane --repo https://github.com/argoproj/argocd-example-apps.git --path plugins/kasane --dest-namespace default --dest-server https://kubernetes.default.svc --config-management-plugin kasane

argocd app list

List applications

# argocd app list [flags]

Example:

List all apps

# argocd app list

List apps by label, in this example we listing apps that are children of another app (aka app-of-apps)

# argocd app list -l app.kubernetes.io/instance=my-app

argocd app delete

Delete an application

# argocd app delete APPNAME [flags]

argocd app diff

Perform a diff against the target and live state.

Synopsis

Perform a diff against the target and live state. Uses ‘diff’ to render the difference. KUBECTL_EXTERNAL_DIFF environment variable can be used to select your own diff tool. Returns the following exit codes: 2 on general errors, 1 when a diff is found, and 0 when no diff is found

# argocd app diff APPNAME [flags]

argocd app edit

Edit application

# argocd app edit APPNAME [flags]

argocd app get

Get application details

# argocd app get APPNAME [flags]

argocd app history

Show application deployment history

# argocd app history APPNAME [flags]

argocd app logs

Get logs of application pods

# argocd app logs APPNAME [flags]

argocd app manifests

Print manifests of an application

# argocd app manifests APPNAME [flags]

argocd app patch

Patch application

# argocd app patch APPNAME [flags]

Example:

Update an application’s source path using json patch

# argocd app patch myapplication --patch='[{"op": "replace", "path": "/spec/source/path", "value": "newPath"}]' --type json

Update an application’s repository target revision using merge patch

# argocd app patch myapplication --patch '{"spec": { "source": { "targetRevision": "master" } }}' --type merge

argocd app rollback

Rollback application to a previous deployed version by History ID, omitted will Rollback to the previous version

# argocd app rollback APPNAME [ID] [flags]

argocd app sync

Sync an application to its target state

# argocd app sync [APPNAME... | -l selector] [flags]

Examples

Sync an app

# argocd app sync my-app

Sync multiples apps

# argocd app sync my-app other-app

Sync apps by label, in this example we sync apps that are children of another app (aka app-of-apps)

# argocd app sync -l app.kubernetes.io/instance=my-app

Sync a specific resource, Resource should be formatted as GROUP:KIND:NAME. If no GROUP is specified then :KIND:NAME

# argocd app sync my-app --resource :Service:my-service
# argocd app sync my-app --resource argoproj.io:Rollout:my-rollout

Specify namespace if the application has resources with the same name in different namespaces

# argocd app sync my-app --resource argoproj.io:Rollout:my-namespace/my-rollout

argocd app wait

Wait for an application to reach a synced and healthy state

# argocd app wait [APPNAME.. | -l selector] [flags]

Examples

Wait for an app

# argocd app wait my-app

Wait for multiple apps

# argocd app wait my-app other-app

Wait for apps by label, in this example we waiting for apps that are children of another app (aka app-of-apps)

# argocd app wait -l app.kubernetes.io/instance=apps

In coming post will see about RBAC in details.

You can follow us on social media, to get some short knowledges regularly.

Google search engine