How do we take a kubernetes cluster-info dump using the kubernetes api

10/24/2018

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: golang code:

coreClient := kubernetesapi.CoreV1()
nodeList, err := coreClient.Nodes().List(metav1.ListOptions{})

This will give me a list of nodes.

Is there an API which returns what "kubectl cluster-info dump" would give. So i can get all the details Programmatically.

-- Bharath
go
kubernetes

3 Answers

10/24/2018

I am afraid this is no such API to do that. kubectl cluster-info dump is also implemented based on k8s sdk.

But you can refer the implementation and customize to your own needs.

https://github.com/kubernetes/kubernetes/blob/6fc89ae92d9d09bd70e74d32c6ba6b3d28e7bec7/pkg/kubectl/cmd/clusterinfo/clusterinfo_dump.go

-- wilbeibi
Source: StackOverflow

10/24/2018

Backup and restore cluster resources:

https://medium.com/@marekbartik/kubernetes-in-production-snapshotting-cluster-state-41bd767ef14

Use ark for cluster backup and resotre:

ark schedule create <SCHEDULE NAME> --schedule "0 7 * * *"

ark restore create --from-backup <BACKUP-NAME>
-- Ijaz Ahmad Khan
Source: StackOverflow

10/24/2018

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
-- mk_sta
Source: StackOverflow