Configure Calicoctl for IBM Cloud Kubernetes Service

5 min read

Configure Calicoctl for IBM Cloud Kubernetes Service

Do you want to have access to your Calico policies in a quick and simple way? We’ve got you covered.

In the IBM Cloud Kubernetes Service, the Calico configuration file can now be generated automatically with just a single command. For clusters 1.10 and above, you can use the new flag --network to download your cluster config.

$ ibmcloud ks cluster-config <CLUSTER_NAME> --network

Downloading the Calico config example

Make sure to update the IBM Cloud Kubernetes Service CLI plugin in the following way:

$ ibmcloud plugin update container-service
ibmcloud plugin update container-service

With the latest CLI, you can download the Calico Config. The location of the calicoctl.cfg file will be displayed, which can be then used to configure calicoctl to access your cluster.

$ ibmcloud ks cluster-config <CLUSTER_NAME> --network
ibmcloud ks cluster-config <CLUSTER_NAME> --network

Installing the Calico binary on MacOS

Here are the steps on how to install the exact version of the calicoctl binary that matches what is running in your Kubernetes cluster. If you already have the right version of calicoctl installed, please proceed to the next section.

Assuming you have kubectl set up for your cluster, follow the steps below.

  1. Find the Calico version you have currently running in your Kubernetes cluster:

    $ calicoVersion=$(kubectl get po -n kube-system -l k8s-app=calico-kube-controllers -o yaml | grep -e "image:.*kube-controllers" | head -1 | cut -d':' -f3)
  2. Download the calicoctl binary:

    $ curl -O -L$calicoVersion/calicoctl-darwin-amd64
  3. Move the binary to your bin directory:

    $ chmod 755 calicoctl-darwin-amd64; sudo mv calicoctl-darwin-amd64 /usr/local/bin/calicoctl

Using the Calico config

Option #1) The CLIs --config flag

Calico has the option to specify the config on every cmd:

$ calicoctl get no --config <YOUR_CALICO_CONFIG>


calicoctl get no --config <YOUR_CALICO_CONFIG>

Note: You can also pass it in as a variable if you set it beforehand $CALICOCNF.

Option #2) Using the config in the default config location

Calico has a default config location (/etc/calico/calicoctl.cfg), and if you move the config to this location, you won’t need to pass the config on every calicoctlcmd, which comes pretty handy.

$ sudo mv <YOUR_CALICO_CONFIG> /etc/calico/calicoctl.cfg
sudo mv <YOUR_CALICO_CONFIG> /etc/calico/calicoctl.cfg

Enjoy the easy operation:

$ calicoctl get nodes
calicoctl get nodes

For more information about setting up Calico, you can check out the IBM Cloud Kubernetes Service docs.

Contact us

If you have questions, engage our team via Slack by registering here and join the discussion in the #general channel on our public IBM Cloud Kubernetes Service Slack.

Be the first to hear about news, product updates, and innovation from IBM Cloud