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

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

Argo CD is a declarative, GitOps continuous delivery tool for Kubernetes. The argocd app command-line interface enables users to manage applications in Argo CD, providing functionalities like listing, creating, deploying, and monitoring applications’ states and more within a Kubernetes cluster. This utility is crucial for DevOps teams needing efficient, automated, and reliable application management catered to modern software development practices.

Use case 1: Listing Applications

Code:

argocd app list --output json|yaml|wide

Motivation:
Listing applications is fundamental when managing multiple applications within Argo CD. It provides an overview of all applications, their statuses, and relevant metadata, helping maintain oversight of your deployment environment. By using different output formats, users can tailor the information for different needs, such as quick checks or integrations with other tools.

Explanation:

  • argocd: This is the base command for Argo CD operations.
  • app list: This subcommand is used to list all applications managed by Argo CD.
  • --output json|yaml|wide: This option determines the format in which the application list will be provided. json and yaml are structured data formats ideal for further processing or human readability, while wide may provide a more detailed tabular view directly in the terminal.

Example Output (for wide format):

NAME         PROJECT  STATUS  HEALTH   SYNCPOLICY  ...
my-app       default  Synced  Healthy  Auto        ...
another-app  team2    OutSync Degraded Manual      ...

Use case 2: Getting Application Details

Code:

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

Motivation:
Fetching detailed information about a specific application is crucial for troubleshooting and analyzing the state, configurations, and history of deployments. It helps in understanding the differences in configurations and issues within specific applications.

Explanation:

  • argocd app get: Fetches the information related to the specified app_name.
  • app_name: The name of the application whose details you want.
  • --output json|yaml|wide: Specifies the format for the output, similar to the listing command.

Example Output (for yaml format):

metadata:
  name: my-app
  project: default
status:
  health: Healthy
  sync:
    status: Synced
spec:
  source:
    repoURL: https://github.com/my-repo.git
    path: apps/my-app

Use case 3: Deploying 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:
Internally deploying an application is essential for setting up new applications or environments, especially within the same cluster. This process leverages the repository to define application configurations, enabling rapid, consistent deployments.

Explanation:

  • argocd app create: Initializes and deploys a new application within Argo CD.
  • app_name: The desired name for your new application.
  • --repo git_repo_url: The Git repository containing the configuration manifests.
  • --path path/to/repo: The path within the repository where the application manifests are located.
  • --dest-server https://kubernetes.default.svc: The target Kubernetes API server URL (commonly the in-cluster server).
  • --dest-namespace ns: The Kubernetes namespace in which the application should be deployed.

Example Output:

application 'my-new-app' created

Use case 4: Deleting an Application

Code:

argocd app delete app_name

Motivation:
Deleting an application is often necessary to remove outdated, deprecated, or test deployments. This process helps maintain a clean and manageable application portfolio within the Kubernetes environment.

Explanation:

  • argocd app delete: This command removes an application from Argo CD.
  • app_name: The name of the application to delete.

Example Output:

application 'my-obsolete-app' deleted

Use case 5: Enabling Application Auto-Sync

Code:

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

Motivation:
Auto-sync ensures your application stays aligned with its declared Git state, automatically reflecting changes. This feature is beneficial for continuous deployment strategies, reducing manual intervention, and enhancing reliability and consistency.

Explanation:

  • argocd app set: Modifies the settings of the specified application.
  • app_name: The name of the application to configure.
  • --sync-policy auto: Enables automatic syncing of the application.
  • --auto-prune: Automatically removes resources that are not defined in the Git repository.
  • --self-heal: Automatically reverts to the defined state in Git if a resource diverges.

Example Output:

application 'critical-app' updated: sync policy set to auto, auto-prune enabled, self-heal enabled

Use case 6: Previewing App Synchronization

Code:

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

Motivation:
Performing a dry-run of the synchronization lets you preview the changes without actually applying them. This preemptive step is crucial for ensuring unexpected changes don’t cause disruptions, offering a safe way to manage updates.

Explanation:

  • argocd app sync: Synchronizes the specified application with the Git repository.
  • app_name: The name of the application to synchronize.
  • --dry-run: Simulates the synchronization process without making actual changes.
  • --prune: Identifies resources that are not present in the Git repository for potential deletion.

Example Output:

Performing dry run for application 'preview-app': No changes detected, 2 resources are pending deletion

Use case 7: Showing Application Deployment History

Code:

argocd app history app_name --output wide|id

Motivation:
Tracking deployment history is vital for auditing changes, troubleshooting, and understanding application evolution. The deployment history provides insights into what changes occurred, when, and by whom, fostering better management and compliance.

Explanation:

  • argocd app history: Retrieves the deployment history of the specified application.
  • app_name: The application of interest.
  • --output wide|id: Specifies the detail level of the output; wide gives comprehensive information, whereas id shows concise change IDs.

Example Output (for wide format):

ID  STATUS  DATE-TIME            MESSAGE
1   Deployed 2023-01-10T12:34   Initial release
2   Deployed 2023-02-14T15:49   Bug fixes

Use case 8: Rolling Back an Application

Code:

argocd app rollback app_name history_id --prune

Motivation:
Rolling back to a previous version is often necessary when new deployments introduce critical issues or bugs. This command facilitates reverting applications to a stable state, minimizing downtime and user impact.

Explanation:

  • argocd app rollback: Reverts an application to a specified deployment identified by history ID.
  • app_name: The specific application to rollback.
  • history_id: The unique identifier of the deployment to which you wish to return.
  • --prune: Ensures removal of resources not present in that specific historical deployment.

Example Output:

Rollback of application 'app-in-trouble' to history ID '2' completed successfully

Conclusion

The argocd app command-line interface provides comprehensive tools for managing applications in a Kubernetes cluster using Argo CD. From deploying and rolling back applications to enabling auto-sync and viewing histories, it not only automates but also streamlines the complexity involved in modern continuous delivery practices. Having mastery of these commands enhances efficiency, reliability, and control over application management workflows.

Related Posts

How to use the command 'kubetail' (with examples)

How to use the command 'kubetail' (with examples)

Kubetail is a powerful and efficient utility to simultaneously tail logs from multiple Kubernetes pods.

Read More
How to Use the Command `cargo package` (with examples)

How to Use the Command `cargo package` (with examples)

The cargo package command is a powerful tool for Rust developers, allowing them to assemble a local package into a distributable tarball (a .

Read More
How to Use the Command 'whence' in Zsh (with examples)

How to Use the Command 'whence' in Zsh (with examples)

The whence command is a builtin utility in the Zsh shell.

Read More