Does kubernetes provide an API in its client library to get the cluster-info dump? I went through its API documentation and could find any API which could actually do this.
What i do now:
kubectl cluster-info dump --output-directory="dumpdir"
What i want:
Using client-go/kubernetes API libraries, make an API call to get this dump from a golang application. Is it possible?
What i know:
There are individual API's for each resource which can provide all the information provided by the cluster-info dump, but i want to do it will a single API call.
For example, this Golang code will give me a list of nodes:
coreClient := kubernetesapi.CoreV1()
nodeList, err := coreClient.Nodes().List(metav1.ListOptions{})
Is there an API which returns what kubectl cluster-info dump would give, so that I can get all the details programmatically?
You can capture API calls by listing the output with verbose option in kubectl cluster-info command:
kubectl cluster-info dump -v 9
For example:
curl -k -v -XGET -H "Accept: application/json, /" -H "User-Agent: kubectl/v1.12.1 (linux/amd64) kubernetes/4ed3216" 'https://10.142.0.3:6443/api/v1/namespaces/kube-system/events'
Get the token for authorization purpose in your cluster:
MY_TOKEN="$(kubectl get secret <default-secret> -o jsonpath='{$.data.token}' | base64 -d)"
Now you can make API call for the target resource:
curl -k -v -H "Authorization : Bearer $MY_TOKEN" https://10.142.0.3:6443/api/v1/namespaces/kube-system/events
Keep in mind that you may require role binding in order to grant view permission for your service account:
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: default-view
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: view
subjects:
- kind: ServiceAccount
name: default
namespace: default
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With