kubernetes

Dump all config + logs from a Kubernetes cluster

Sometimes you want to take a snapshot of a Kubernetes cluster to inventory what objects are deployed and what logs are showing for the pods that are deployed.

You could query the API server for this information or use kubectl to look for it (e.g. kubectl describe po <pod> & kubectl logs <pod>, but that could take some time.

There's a neat utility built into kubectl that does just this task. You can use the kubectl cluster-info dump command.

Example

 $ ./kubectl cluster-info dump -n gimbal-contour
{
    "selfLink": "/api/v1/nodes",
    "resourceVersion": "4187500",
    "Items": [
        {
            "name": "kubenuk",
            "selfLink": "/api/v1/nodes/kubenuk",
            "uid": "8a5b44c4-8b60-11e8-8a25-001fc69ce05d",
            "resourceVersion": "4187489",
            "creationTimestamp": "2018-07-19T14:32:18Z",
            "labels": {
                "beta.kubernetes.io/arch": "amd64",
                "beta.kubernetes.io/os": "linux",
                "kubernetes.io/hostname": "kubenuk",
                "node-role.kubernetes.io/master": ""
            },
            "annotations": {
                "kubeadm.alpha.kubernetes.io/cri-socket": "/var/run/dockershim.sock",
                "node.alpha.kubernetes.io/ttl": "0",
                "projectcalico.org/IPv4Address": "10.52.131.218/24",
                "volumes.kubernetes.io/controller-managed-attach-detach": "true"
            },
            "Spec": {
                "PodCIDR": "192.168.0.0/24",
                "ExternalID": "kubenuk",
                "ProviderID": "",
                "Unschedulable": false,
                "Taints": null,

Dump ALL

If you want everything from the cluster (assuming you have proper RBAC permissions) you can use this command:

$ kubectl cluster-info dump --all-namespaces --output-directory=./test

Output

$ ll ./test/gimbal-contour                                      
total 96K
drwxr-xr-x 2 steve steve 4.0K Sep  5 20:21 contour-6b4664bd64-vbntp
-rw-r--r-- 1 steve steve  135 Sep  7 23:14 daemonsets.json
-rw-r--r-- 1 steve steve 9.4K Sep  7 23:14 deployments.json
drwxr-xr-x 2 steve steve 4.0K Sep  5 20:21 envoy-27z2c
-rw-r--r-- 1 steve steve  114 Sep  7 23:14 events.json
-rw-r--r-- 1 steve steve  12K Sep  7 23:14 pods.json
-rw-r--r-- 1 steve steve  45K Sep  7 23:14 replicasets.json
-rw-r--r-- 1 steve steve  130 Sep  7 23:14 replication-controllers.json
-rw-r--r-- 1 steve steve 4.0K Sep  7 23:14 services.json
Author image

About Steve Sloka