Argo CD CLI Installation and Commands

0
12056
Argo CD CLI Install and commands

So far, we have seen Argo CD with UI mostly and now let’s see another feature provided by Argo CD, which CLI to manage the Argo CD. CLI provides almost same feature as GUI, you can perform most of the operation done via UI using CLI. Let’s see more of the useful commands in this post.

Before starting, lets see how to install Argo CD CLI in different operating systems. You can download the latest Argo CD version from the latest release page of this repository, which will include the Argo CD CLI.

Linux

ArchLinux
# pacman -S argocd
Homebrew
# brew install argocd
Download With Curl
Download latest version
# curl -sSL -o /usr/local/bin/argocd https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-amd64
# chmod +x /usr/local/bin/argocd

Download selected version

Set VERSION replacing <TAG> in the command below with the version of Argo CD you would like to download:

# VERSION=<TAG>

Select desired TAG from https://github.com/argoproj/argo-cd/releases

# curl -sSL -o /usr/local/bin/argocd https://github.com/argoproj/argo-cd/releases/download/$VERSION/argocd-linux-amd64
# chmod +x /usr/local/bin/argocd

Mac

# brew install argocd
VERSION=$(curl --silent "https://api.github.com/repos/argoproj/argo-cd/releases/latest" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')

Replace VERSION in the command below with the version of Argo CD you would like to download:

Windows

Download With PowerShell: Invoke-WebRequest

You can view the latest version of Argo CD at the link above or run the following command to grab the version:

$version = (Invoke-RestMethod https://api.github.com/repos/argoproj/argo-cd/releases/latest).tag_name

Replace $version in the command below with the version of Argo CD you would like to download:

$url = "https://github.com/argoproj/argo-cd/releases/download/" + $version + "/argocd-windows-amd64.exe"
$output = "argocd.exe"

Invoke-WebRequest -Uri $url -OutFile $output

Also please note you will probably need to move the file into your PATH.

After finishing the instructions above, you should now be able to run argocd commands.

Prerequisites:

Argo CD Commands:

For now, we have completed the installation and hope you have the argoCD up and running already. Now let’s check the available commands in Argo CD. As there are multiple commands, let’s see with serios of posts. Here is first set of commands,

Video Demo

Version:

To check the argo cd version detail please use following commands.

# argocd version [flags]

Print the full version of client and server to stdout

# argocd version
argocd: v2.3.4+ac8b7df
  BuildDate: 2022-05-18T13:06:25Z
  GitCommit: ac8b7df9467ffcc0920b826c62c4b603a7bfed24
  GitTreeState: clean
  GoVersion: go1.17.9
  Compiler: gc
  Platform: linux/amd64
argocd-server: v2.4.6+a48bca0
  BuildDate: 2022-07-12T22:31:17Z
  GitCommit: a48bca03c79b6d63be0c34d6094831bc6916b3bc
  GitTreeState: clean
  GoVersion: go1.18.3
  Compiler: gc
  Platform: linux/amd64
  Kustomize Version: v4.4.1 2021-11-11T23:36:27Z
  Helm Version: v3.8.1+g5cb9af4
  Kubectl Version: v0.23.1
  Jsonnet Version: v0.18.0

Note: To get the server version details, you should login to the argocd instance. otherwise the command will be hung endless. Please refer login section to login instance.

Print only full version of the client – no connection to server will be made

# argocd version --client
argocd: v2.3.4+ac8b7df
  BuildDate: 2022-05-18T13:06:25Z
  GitCommit: ac8b7df9467ffcc0920b826c62c4b603a7bfed24
  GitTreeState: clean
  GoVersion: go1.17.9
  Compiler: gc
  Platform: linux/amd64

Print the full version of client and server in JSON format

# argocd version -o json
{
  "client": {
    "Version": "v2.3.4+ac8b7df",
    "BuildDate": "2022-05-18T13:06:25Z",
    "GitCommit": "ac8b7df9467ffcc0920b826c62c4b603a7bfed24",
    "GitTag": "",
    "GitTreeState": "clean",
    "GoVersion": "go1.17.9",
    "Compiler": "gc",
    "Platform": "linux/amd64",
    "KubectlVersion": "v0.23.1"
  },
  "server": {
    "Version": "v2.4.6+a48bca0",
    "BuildDate": "2022-07-12T22:31:17Z",
    "GitCommit": "a48bca03c79b6d63be0c34d6094831bc6916b3bc",
    "GitTreeState": "clean",
    "GoVersion": "go1.18.3",
    "Compiler": "gc",
    "Platform": "linux/amd64",
    "KustomizeVersion": "v4.4.1 2021-11-11T23:36:27Z",
    "HelmVersion": "v3.8.1+g5cb9af4",
    "KubectlVersion": "v0.23.1",
    "JsonnetVersion": "v0.18.0"
  }
}

Print only client and server core version strings in YAML format

# argocd version --short -o yaml
client:
  argocd: v2.3.4+ac8b7df
server:
  argocd-server: v2.4.6+a48bca0

Login:

Any operation if you want to perform on argocd using CLI, you should login to argo cd instance. Here is the pattern for your reference.

# argocd login SERVER [flags]

To login to argocd instance using IP/URL with local users

# argocd login 20.237.43.19 --username admin

When you login using the above command it will ask you to confirm to proceed without SSL, provide Y.(yes)

To login to argocd instance using IP/URL with sso

# argocd login  20.237.43.19  --sso

Replace the IP with your loadbalancer IP or URL

Context:

To Switch between contexts using argocd, follow the below pattern.

# argocd context [CONTEXT] [flags]

To list all available cluster contexts,

# argocd context
CURRENT  NAME               SERVER
         20.85.176.86:443   20.85.176.86:443
         20.241.200.211     20.241.200.211
         20.237.24.56:443   20.237.24.56:443
         52.188.76.212:443  52.188.76.212:443
         20.121.175.69      20.121.175.69
*        20.237.43.19       20.237.43.19

To delete the context from the list,

# argocd context --delete 20.81.21.237
Context '20.81.21.237' deleted

Clusters:

Here is the pattern for the running the cluster commands

# argocd cluster [flags]

List all known clusters in JSON format:

# argocd cluster list -o json
[
  {
    "server": "https://kubernetes.default.svc",
    "name": "in-cluster",
    "config": {
      "tlsClientConfig": {
        "insecure": false
      }
    },
    "connectionState": {
      "status": "Unknown",
      "message": "Cluster has no applications and is not being monitored.",
      "attemptedAt": "2022-07-18T17:17:05Z"
    },
    "info": {
      "connectionState": {
        "status": "Unknown",
        "message": "Cluster has no applications and is not being monitored.",
        "attemptedAt": "2022-07-18T17:17:05Z"
      },
      "cacheInfo": {},
      "applicationsCount": 0
    }
  }
]

Add a target cluster configuration to ArgoCD. The context must exist in your kubectl config:

# argocd cluster add arn:aws:eks:us-west-2:901115694977:cluster/aeks
WARNING: This will create a service account `argocd-manager` on the cluster referenced by context `arn:aws:eks:us-west-2:901115694977:cluster/aeks` with full cluster level admin privileges. Do you want to continue [y/N]? y
INFO[0003] ServiceAccount "argocd-manager" created in namespace "kube-system"
INFO[0003] ClusterRole "argocd-manager-role" created
INFO[0003] ClusterRoleBinding "argocd-manager-role-binding" created
Cluster 'https://C21BD6758D425BBB0CE90BCC490CD99C.gr7.us-west-2.eks.amazonaws.com' added

Get specific details about a cluster-in plain text(wide) format:

# argocd cluster list
SERVER                                                                    NAME                                             VERSION  STATUS      MESSAGE                                                  PROJECT
https://C21BD6758D425BBB0CE90BCC490CD99C.gr7.us-west-2.eks.amazonaws.com  arn:aws:eks:us-west-2:901115694977:cluster/aeks  1.22+    Successful
https://kubernetes.default.svc                                            in-cluster                                                Unknown     Cluster has no applications and is not being monitored.
# argocd cluster get in-cluster -o wide
Cluster information
  Server URL:            https://kubernetes.default.svc
  Server Name:           in-cluster
  Server Version:
  Namespaces:            all namespaces
TLS configuration
  Client cert:           false
  Cert validation:       true
Authentication
  Basic authentication:  false
  oAuth authentication:  false
  AWS authentication:    false

Remove a target cluster context from ArgoCD

# argocd cluster rm https://C21BD6758D425BBB0CE90BCC490CD99C.gr7.us-west-2.eks.amazonaws.com
Cluster 'https://C21BD6758D425BBB0CE90BCC490CD99C.gr7.us-west-2.eks.amazonaws.com' removed

In coming post will see about repositories and applications commands. In last will see about RBAC in details.

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

Google search engine