How to use the command 'argocd app' (with examples)

How to use the command 'argocd app' (with examples)

The argocd app command-line interface is used to manage applications in Argo CD. Argo CD is a declarative continuous deployment tool for Kubernetes. This command provides various subcommands to perform operations such as listing applications, getting application details, deploying applications, deleting applications, enabling auto-sync, previewing synchronization, showing deployment history, and rolling back deployment to a previous version.

Use case 1: List applications

Code:

argocd app list --output json|yaml|wide

Motivation: Listing applications provides an overview of all the applications managed by Argo CD. This can be useful for monitoring, troubleshooting, or obtaining information about application names, repository URLs, and health status.

Explanation:

  • --output: Specifies the output format for the list, such as JSON, YAML, or wide.
    • json: Output in JSON format.
    • yaml: Output in YAML format.
    • wide: Output in a tabular format with more details.

Example output:

APP NAME        PROJECT     STATUS   HEALTH   SYNCPOLICY   ... 
my-app          my-project  Synced   Healthy  Manual       ...
another-app     my-project  OutOfSyncDegraded   Auto        ...

Use case 2: Get application details

Code:

argocd app get app_name --output json|yaml|wide

Motivation: Getting application details provides specific information about a particular application. This can be helpful for troubleshooting, reviewing configuration, or retrieving application metadata.

Explanation:

  • app_name: Specifies the name of the application to retrieve details for.
  • --output: Specifies the output format for the details, such as JSON, YAML, or wide.
    • json: Output in JSON format.
    • yaml: Output in YAML format.
    • wide: Output in a tabular format with more details.

Example output:

Name:                     my-app
Project:                  my-project
URL:                      https://github.com/user/repo
Path:                     path/to/repo
Destination Server:       https://kubernetes.default.svc
Destination Namespace:    ns
Sync Policy:              Manual
...

Use case 3: Deploy application internally

Code:

argocd app create app_name --repo git_repo_url --path path/to/repo --dest-server https://kubernetes.default.svc --dest-namespace ns

Motivation: Deploying applications internally allows for easily deploying applications to the same cluster that Argo CD is running in. This can be useful for quickly testing and deploying applications on the local cluster.

Explanation:

  • app_name: Specifies the name for the application being created.
  • --repo: Specifies the git repository URL where the application configuration is stored.
  • --path: Specifies the path within the repository where the application manifests are located.
  • --dest-server: Specifies the destination Kubernetes server where the application should be deployed (e.g., https://kubernetes.default.svc).
  • --dest-namespace: Specifies the destination namespace within the Kubernetes cluster where the application should be deployed.

Example output: No output is displayed if the deployment is successful.

Use case 4: Delete an application

Code:

argocd app delete app_name

Motivation: Deleting an application removes it from Argo CD, stopping its synchronization and deleting the associated resources. This can be helpful when an application is no longer needed or to clean up resources after testing.

Explanation:

  • app_name: Specifies the name of the application to be deleted.

Example output: No output is displayed if the deletion is successful.

Use case 5: Enable application auto-sync

Code:

argocd app set app_name --sync-policy auto --auto-prune --self-heal

Motivation: Enabling application auto-sync automates the synchronization process for an application, reducing the need for manual intervention. Auto-sync ensures that the application is always up-to-date with the desired state, and it can automatically prune and self-heal the application.

Explanation:

  • app_name: Specifies the name of the application to enable auto-sync for.
  • --sync-policy auto: Sets the synchronization policy to automatic.
  • --auto-prune: Enables automatic pruning of resources that are no longer part of the application manifest.
  • --self-heal: Enables automatic self-healing of the application by recovering from any inconsistencies.

Example output: No output is displayed if the configuration is successfully updated.

Use case 6: Preview app synchronization without affecting cluster

Code:

argocd app sync app_name --dry-run --prune

Motivation: Previewing app synchronization allows you to see what changes will be applied to the cluster without actually deploying them. This helps to verify the expected changes and ensure that the synchronization process will not have any unintended consequences.

Explanation:

  • app_name: Specifies the name of the application to preview the synchronization for.
  • --dry-run: Performs a dry run of the synchronization, displaying the changes that would be made without actually applying them.
  • --prune: Includes pruning of resources that are no longer part of the application manifest.

Example output: The output displays the changes that would be made during synchronization without actually applying them.

Use case 7: Show application deployment history

Code:

argocd app history app_name --output wide|id

Motivation: Showing application deployment history provides a historical view of the different deployments made for an application. This can be useful for tracking changes, identifying issues, or reverting to a previous known state.

Explanation:

  • app_name: Specifies the name of the application to show the deployment history for.
  • --output: Specifies the output format for the history, including wide or only the deployment ID.
    • wide: Output in a tabular format with more details.
    • id: Output only the deployment ID.

Example output:

DATE                         REVISION   DEPLOYMENT STATUS   ...
2022-01-01 10:00:00          1234567    Successful          ...
2021-12-31 16:30:00          9876543    Failed              ...

Use case 8: Rollback application to a previous deployed version

Code:

argocd app rollback app_name history_id --prune

Motivation: Rolling back an application to a previous deployed version allows you to revert to a known working state if a deployment has caused issues or introduced unexpected changes. This can be useful for quickly recovering from errors or inconsistencies.

Explanation:

  • app_name: Specifies the name of the application to rollback.
  • history_id: Specifies the deployment history ID to rollback to.
  • --prune: Includes pruning of resources that are no longer part of the application manifest.

Example output: No output is displayed if the rollback is successful.

Conclusion:

The argocd app command-line interface provides powerful functionality for managing applications in Argo CD. With its various subcommands, you can easily list applications, get application details, deploy applications, delete applications, enable auto-sync, preview synchronization, show deployment history, and rollback deployments. These capabilities make it easier to work with applications in Argo CD and ensure smooth and efficient application management.

Related Posts

How to Use ssh-copy-id Command (with examples)

How to Use ssh-copy-id Command (with examples)

1. Copy your keys to the remote machine The ssh-copy-id command allows you to easily copy your public key to a remote machine’s authorized_keys file.

Read More
How to use the command cupsctl (with examples)

How to use the command cupsctl (with examples)

Cupsctl is a command-line tool used to update or query the configuration of the cupsd.

Read More
How to use the command jpegoptim (with examples)

How to use the command jpegoptim (with examples)

JPEGoptim is a command-line tool that allows users to optimize JPEG images by reducing their file size while retaining the quality of the images.

Read More