This guide provides installation and basic usage instructions for calicoctl (the Calico command-line tool) and kubectl (the Kubernetes command-line tool).
1. calicoctl
calicoctl is used to manage Calico network policies, IP address management, and other Calico configurations.
1.1 Installation
Download the calicoctl binary:
The following command downloads a specific version (v3.21.2). For the latest version, please check the Project Calico releases page.
curl-ocalicoctl-L"https://github.com/projectcalico/calicoctl/releases/download/v3.21.2/calicoctl"# Note: The original command had an extra -O flag which is not needed with -o.
calicoctl needs to know how to access your datastore (etcd or Kubernetes API). This can be configured via environment variables or a configuration file.
Method 1: Environment Variables
You can set these per command or export them for your session.
Per command:
(Note: sudo might be needed if your KUBECONFIG points to a root-owned file or if Calico resources require elevated privileges, but often calicoctl can be run by a user with appropriate kubeconfig access.)
For the session:
Method 2: Configuration File
You can create a configuration file at /etc/calico/calicoctl.cfg.
Create the directory and file:
Paste the following content into /etc/calico/calicoctl.cfg. Ensure the kubeconfig path is correct for your system.
(Generalized the kubeconfig path to ~/.kube/config and added a comment.)
Note: If this config file exists and is readable, calicoctl should pick up these settings automatically. You might need sudo to run calicoctl if it needs to read this root-owned config file, or adjust permissions on the file/directory.
1.3 Usage Examples
(Assuming configuration is done via environment variables or the config file)
List Calico nodes:
List Calico workload endpoints:
2. kubectl
kubectl is the primary command-line tool for interacting with a Kubernetes cluster.
2.1 Installation
Download the latest stable kubectl binary:
This command fetches the version string for the latest stable release and downloads the corresponding binary.
sudo DATASTORE_TYPE=kubernetes KUBECONFIG=~/.kube/config calicoctl get nodes
export DATASTORE_TYPE=kubernetes
export KUBECONFIG=~/.kube/config
# Now run calicoctl commands
calicoctl get workloadendpoints
sudo mkdir -p /etc/calico
# sudo vi /etc/calico/calicoctl.cfg
# /etc/calico/calicoctl.cfg
apiVersion: projectcalico.org/v3
kind: CalicoAPIConfig
metadata:
spec:
datastoreType: "kubernetes"
kubeconfig: "~/.kube/config" # Or provide the full path, e.g., /home/youruser/.kube/config
calicoctl get nodes
calicoctl get workloadendpoints
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
# Note: Original URL "https://storage.googleapis.com/kubernetes-release/..." is older.
# Using "https://dl.k8s.io/..." which is the current official way.