Skip to content

How to use CLI Tool

Eunsang edited this page Dec 15, 2022 · 7 revisions

Build a CLI Tool(cbadm)

$ git clone https://github.com/cloud-barista/cb-ladybug.git
$ cd cb-ladybug
$ go build -o cbadm src/grpc-api/cbadm/cbadm.go
$ mv ./cbadm /usr/local/bin/cbadm
$ chmod +x cbadm

Usage

cbadm [command]
  • Available Commands:

    • completion   generate the autocompletion script for the specified shell
    • config           This is a configuration command
    • create           This is a create command
    • delete           This is a delete command
    • get                This is a get command
    • healthy         This is a checking CB-Ladybug's health command
    • help              Help about any command
    • version         This is a command to check the version of cbadm
  • Flags:

    • -c,    --config string    configuration file path
    • -d,    --data string     input string data
    • -f,     --file string       filepath
    • -h,    --help                help for cbadm
    •          --name string    name
    • -n,    --namespace string    cloud-baristar namespace
    • -o,    --output string    output format (json/yaml) (default "yaml")
  • Use "cbadm [command] --help" for more information about a command.

Create

  • filepath type (-f flag)
$ cbadm create [cluster/node] -f ${URL}
$ cbadm create [cluster/node] -f ${FILEPATH}
$ cbamd create [cluster/node] -f ${STDIN}

# example
# cluster
$ cbadm create cluster -f http://abc.com/sample/create-cluster.yaml
$ cbadm create cluster -f ./cluster.yaml
$ cbadm create cluster -f - <<EOF
name: cb-cluster
label: lab.
description: create a cluster test
controlPlane:
  - connection: config-aws-ap-northeast-1
    count: 3
    spec: t2.medium
worker:
  - connection: config-ibm-jp-osa
    count: 1
    spec: bx2-2x8
config:
  kubernetes:
    networkCni: kilo
    podCidr: 10.244.0.0/16
    serviceCidr: 10.96.0.0/12
    serviceDnsDomain: cluster.local
EOF

# node
# only worker node
$ cbadm create node -f http://abc.com/sample/add-node.yaml
$ cbadm create node -f ./node.json
$ cbadm create node --cluster cb-cluster -f - <<EOF
worker: 
  - connection: config-aws-tokyo
    count: 1
    spec: t2.medium
EOF
  • data string type (-d flag)
$ cbadm create cluster -d \ 'STRING JSON or YAML'
$ cbadm create node --cluster ${CLUSTER_NAME} -d \ 'STRING JSON or YAML'

# example
# cluster
$ cbadm create cluster -d \
'{
    "name": "cb-cluster",
    "config": {
      "kubernetes": {
        "networkCni": "canal",
        "podCidr": "10.244.0.0/16",
        "serviceCidr": "10.96.0.0/12",
        "serviceDnsDomain": "cluster.local"
      }
    },
    "controlPlane": [
      {
        "connection": "config-aws-ap-northeast-1",
        "count": 3,
        "spec": "t2.medium"
      }
    ],
    "worker": [
      {
        "connection": "config-ibm-jp-osa",
        "count": 1,
        "spec": "bx2-2x8"
      }
    ]
}'

# node
# only worker node
$ cbadm create node --cluster cb-cluster -d \
'{
    "worker": [
      {
        "connection": "config-aws-tokyo",
        "count": 1,
        "spec": "t2.medium"
      }
    ]
}'

Get

  • Cluster
$ cbadm get cluster
$ cbadm get cluster ${CLUSTER_NAME}
$ cbadm get cluster --name ${CLUSTER_NAME}

# example
$ cbadm get cluster
$ cbadm get cluster cb-cluster
$ cbadm get cluster --name cb-cluster
  • Node
$ cbadm get node --cluster ${CLUSTER_NAME}
$ cbadm get node ${NODE_NAME} --cluster ${CLUSTER_NAME}
$ cbadm get node --name ${NODE_NAME} --cluster ${CLUSTER_NAME}

# example
$ cbadm get node --cluster cb-cluster
$ cbadm get node w-1-cj3sj --cluster cb-cluster
$ cbadm get node --name w-1-cj3sj --cluster cb-cluster

Delete

  • Cluster
$ cbadm delete cluster ${CLUSTER_NAME}
$ cbadm delete cluster --name ${CLUSTER_NAME}

# example
$ cbadm delete cluster cb-cluster
$ cbadm delete cluster --name cb-cluster
  • Node
$ cbadm delete node ${NODE_NAME} --cluster ${CLUSTER_NAME}
$ cbadm delete node --name ${NODE_NAME} --cluster ${CLUSTER_NAME}

# example
$ cbadm delete node w-1-cj3sj --cluster cb-cluster
$ cbadm delete node --name w-1-cj3sj --cluster cb-cluster

Config

$ cbadm config
$ cbadm config view
$ cbadm config add-context cfg1 \
 --namespace cb-ns \
 --ladybug_server_addr 127.0.0.1:50254 \
 --ladybug_timeout 1000s \
 --ladybug_endpoint localhost:6834 \
 --ladybug_sample_rate 1  \
 --ladybug_service_name grpc_ladybug_client \

$ cbadm config get-context ${CONTEXT_NAME}
$ cbadm config delete-context ${CONTEXT_NAME}

$ cbadm config current-context
$ cbadm config current-context ${CONTEXT_NAME}
$ cbadm config set-namespace ${NAMESPACE_NAME}