inspector

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2024 License: MIT Imports: 20 Imported by: 0

README

Inspector

Go Reference GitHub go.mod Go version Go Report Card GitHub Tests

Before using inspector you need to have kubectl binary installed and configured (config file ${HOME}/.kube/config).

inspector is a CLI tool and a Kubernetes plugin for running Cluster and Ingress Conroller diagnostics, collecting Cluster and Ingress Controller logs and generating reports.

How to install inspector

How to install it and use as a CLI tool
  1. Install Go binary

    go install github.com/qba73/inspector/cmd/inspector@latest
    
  2. Get help:

    inspector -h
    
    Usage:
    
       inspector [-v] [-h] [-n] <namespace>
    
    Collect K8s and NIC diagnostics in the given namespace
    
    In verbose mode (-v), prints out progess, steps and all data points to stdout.
    
  3. Collect data points from default namespace

    inspector -n default > default.json
    
  4. Collect data points from nginx-ingress namespace

    inspector -n nginx-ingress > nginx-ingress.json
    
How to install it and use as a kubectl plugin
  1. Clone the repo.

  2. Build inspector.

    go build -o kubectl-inspector ./cmd/inspector/main.go
    
  3. Copy the binary to a dir in your $HOME, for example:

    cp kubectl-inspector /usr/local/bin
    
  4. Verify if the kubectl discovers the plugin:

    kubectl plugin list
    
    [...]
    /usr/local/bin/kubectl-inspector
    
  5. Verify inspector can be run using kubectl:

    kubectl inspector -h
    
    Usage:
    
       inspector [-h] [-v] [-n] namespace
    
    Collect K8s and Ingress Controller diagnostics in the given namespace.
    
    In verbose mode (-v), prints out progess, steps and all data points to stdout.
    
  6. Collect data points from default namespace

    Note that inspector's default namespace is default.

    kubectl inspector > default.json
    
  7. Collect data points from nginx-ingress namespace

    kubectl inspector -n nginx-ingress > nginx-ingress.json
    

How it works

The program collects K8s cluster and NGINX Ingress Controller diagnostics data. It prints out data in the JSON format to the stdout. This allows the output to be piped to other tools (for example jq) for further parsing and processing.

Collected data points

Currently inspector collects following data points:

  • K8s version
  • K8s cluster id
  • Number of nodes in the cluster
  • K8s platform name
  • Pods
  • Logs from pods
  • Events
  • ConfigMaps
  • Services
  • Deployments
  • StatefulSets
  • ReplicaSets
  • Leases
  • CRDs
  • IngressClasses
  • Ingresses
  • IngressAnnotations

Planned:

  • Nodes metrics
  • Ingress Controller stats, options and configuration

Future releases will add support for collecting K8s Gateway API diagnostics.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Main

func Main() int

Main runs the inspector program.

func ReportJSON added in v0.0.2

func ReportJSON(rep Report) (string, error)

ReportJSON returns collected metrics in a JSON format.

Types

type Client

type Client struct {
	Verbose       bool
	K8sClient     kubernetes.Interface
	CRDClient     *crd.Clientset
	MetricsClient *metrics.Clientset
}

Client is an inspector client.

func BuildClientFromKubeConfig

func BuildClientFromKubeConfig() (*Client, error)

BuildClientFromKubeConfig builds an inspector client ready to interact with the K8s cluster.

func (*Client) ClusterID

func (c *Client) ClusterID(ctx context.Context) (string, error)

ClusterID returns kube-system namespace UID representing K8s clusterID.

func (*Client) ClusterNodes added in v0.0.2

func (c *Client) ClusterNodes(ctx context.Context) (*corev1.NodeList, error)

ClusterNodes returns a list of nodes in a cluster.

func (*Client) ClusterVersion

func (c *Client) ClusterVersion() (string, error)

ClusterVersion returns K8s version.

func (*Client) ConfigMaps added in v0.0.2

func (c *Client) ConfigMaps(ctx context.Context, namespace string) (*corev1.ConfigMapList, error)

ConfigMaps returns a list of config maps for a given namespace.

func (*Client) CustomResourceDefinitions added in v0.0.2

func (c *Client) CustomResourceDefinitions(ctx context.Context) (*apiextv1.CustomResourceDefinitionList, error)

CustomResourceDefinitions returns a list of CRDs in a cluster.

func (*Client) Deployments added in v0.0.2

func (c *Client) Deployments(ctx context.Context, namespace string) (*appsv1.DeploymentList, error)

Deployments returns a list of deployments in a given namespace.

func (*Client) Events added in v0.0.2

func (c *Client) Events(ctx context.Context, namespace string) (*corev1.EventList, error)

Events returns events for a given namespace.

func (*Client) IngressClasses added in v0.0.2

func (c *Client) IngressClasses(ctx context.Context) (*netv1.IngressClassList, error)

IngressClasses returns a list of ingress classes in a cluster.

func (*Client) Ingresses added in v0.0.2

func (c *Client) Ingresses(ctx context.Context, namespace string) (*netv1.IngressList, error)

Ingresses returns a list of ingresses in a given namespace.

func (*Client) Leases added in v0.0.2

func (c *Client) Leases(ctx context.Context, namespace string) (*coordv1.LeaseList, error)

Leasess returns a list of leases in a given namespace.

func (*Client) NodeMetrics added in v0.0.2

func (c *Client) NodeMetrics(ctx context.Context) (*v1beta1.NodeMetricsList, error)

NodeMetrics returns a list of node metrics in a cluster.

func (*Client) Nodes

func (c *Client) Nodes(ctx context.Context) (int, error)

Nodes returns the total number of nodes in a cluster.

func (*Client) Platform

func (c *Client) Platform(ctx context.Context) (string, error)

Platform returns K8s platform name.

func (*Client) PodMetrics added in v0.0.2

func (c *Client) PodMetrics(ctx context.Context, namespace string) (*v1beta1.PodMetricsList, error)

PodMetrics returns a list of pods metrics in a given namespace.

func (*Client) Podlogs

func (c *Client) Podlogs(ctx context.Context, namespace string) (map[string]string, error)

Podlogs returns logs from pods in a given namespace.

func (*Client) Pods

func (c *Client) Pods(ctx context.Context, namespace string) (*corev1.PodList, error)

Pods returns list of pods in a given namespace.

func (*Client) ReplicaSets added in v0.0.2

func (c *Client) ReplicaSets(ctx context.Context, namespace string) (*appsv1.ReplicaSetList, error)

ReplicaSets returns a list of replica sets in a given namespace.

func (*Client) Report

func (c *Client) Report(ctx context.Context, namespace string) (Report, error)

RunDiagnostics collects cluster data points for a given namespace.

func (*Client) Services added in v0.0.2

func (c *Client) Services(ctx context.Context, namespace string) (*corev1.ServiceList, error)

Services returns a list of services for a given namespace.

func (*Client) StatefulSets added in v0.0.2

func (c *Client) StatefulSets(ctx context.Context, namespace string) (*appsv1.StatefulSetList, error)

StatefulSets returns a list of [stateful sets] in a given namespace.

type Report

type Report struct {
	K8sVersion     string                                 `json:"k8s_version"`
	ClusterID      string                                 `json:"cluster_id"`
	Nodes          int                                    `json:"nodes"`
	Platform       string                                 `json:"platform"`
	Pods           *corev1.PodList                        `json:"pods"`
	Podlogs        map[string]string                      `json:"pod_logs"`
	Events         *corev1.EventList                      `json:"events"`
	ConfigMaps     *corev1.ConfigMapList                  `json:"config_maps"`
	Services       *corev1.ServiceList                    `json:"services"`
	Deployments    *appsv1.DeploymentList                 `json:"deployments"`
	StatefulSets   *appsv1.StatefulSetList                `json:"stateful_sets"`
	ReplicaSets    *appsv1.ReplicaSetList                 `json:"replica_sets"`
	Leases         *coordv1.LeaseList                     `json:"leases"`
	IngressClasses *netv1.IngressClassList                `json:"ingress_classes"`
	Ingresses      *netv1.IngressList                     `json:"ingresses"`
	CRDs           *apiextv1.CustomResourceDefinitionList `json:"crds"`
	ClusterNodes   *corev1.NodeList                       `json:"cluster_nodes"`
}

Report holds collected data points.

Directories

Path Synopsis
cmd
inspector
inspector generates K8s cluster diagnostics reports.
inspector generates K8s cluster diagnostics reports.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL