Generating Kubernetes pod CIDR networks with kubectl and jq


I’ve been looking into solutions to advertise pod CIDR blocks to devices outside of my Kubernetes cluster network. The Calico and kube-router projects both have working solutions to solve this problem so I’m evaluating both products. While watching the kube-router BGP demo the instructor used kubectl and jq to display the CIDR blocks assigned to each Kubernetes worker:

$ kubectl get nodes -o json | jq '.items[] | .spec'

{
  "externalID": "kubworker1.prefetch.net",
  "podCIDR": "10.1.0.0/24"
}
{
  "externalID": "kubworker2.prefetch.net",
  "podCIDR": "10.1.4.0/24"
}
{
  "externalID": "kubworker3.prefetch.net",
  "podCIDR": "10.1.1.0/24"
}
{
  "externalID": "kubworker4.prefetch.net",
  "podCIDR": "10.1.2.0/24"
}
{
  "externalID": "kubworker5.prefetch.net",
  "podCIDR": "10.1.3.0/24"
}

This is a cool use of the kubectl JSON output option and jq. Stashing this away here for safe keeping. :)

This article was posted by Matty on 2018-02-20 15:58:11 -0500 -0500