CLI Usage

The kubectl-ka plugin provides commands to retrieve Kubernetes resources from both live cluster and KubeArchive, as well as logs from archived resources. The plugin is designed to mimic the kubectl-get and kubectl-logs commands, providing a consistent interface for accessing both current and historical data.

Available Commands

The plugin supports the following commands:

  • get - Retrieve Kubernetes resources from both live cluster and KubeArchive

  • logs - Retrieve container logs from archived resources

  • config - Manage persistent configuration for different clusters

  • completion - Generate shell autocompletion scripts (limited functionality)

All commands support the standard kubectl configuration flags plus KubeArchive-specific options. For detailed configuration information, see CLI Configuration.

get Command

Retrieve Kubernetes resources from both the live cluster and KubeArchive. The command merges and displays results together.

Syntax

kubectl ka get [RESOURCE[.VERSION[.GROUP]]] [flags]

Resource Specification

You can specify resources in multiple formats:

  • pods - Resource name only (discovers version and group automatically)

  • jobs.batch - Resource with group (discovers preferred version)

  • jobs.v1.batch - Fully qualified resource specification

The plugin supports resource names, short names, and singular forms. For example, pods, pod, po resolve to the Pod resource.

Options

Flag Description Default

--all-namespaces, -A

List resources across all namespaces

false

--namespace, -n

Kubernetes namespace to use for this request

(from kubeconfig)

--output, -o

Output format: json, yaml, or table

table

--selector, -l

Label selector to filter resources

(none)

--in-cluster

Include resources from the live Kubernetes cluster

true

--archived

Include resources from KubeArchive

true

Providing --in-cluster shows only in-cluster resources. Providing --archived shows only archived resources. Providing both or neither flag shows all resources.

Examples

# Get pods from current namespace (shows both live and archived)
kubectl ka get pods

# Get pods from all namespaces
kubectl ka get pods --all-namespaces

# Get a specific pod resource in YAML format
kubectl ka get po my-pod -n my-ns -o yaml

# Get deployments with multiple labels
kubectl ka get deployments -l 'tier=frontend,env in (staging,production)'

# Get only live cluster resources (no archive query)
kubectl ka get pods --in-cluster

# Get only archived resources (no cluster query)
kubectl ka get pods --archived

The plugin merges results from both live cluster and KubeArchive, showing availability indicators for each resource. The command deduplicates resources with the same UID from both sources and shows them once with both availability flags set.

You cannot use label selectors (-l) together with specifying a resource name. Use either a label selector to filter multiple resources (kubectl ka get pods -l app=nginx) OR specify a specific resource name (kubectl ka get pod nginx-pod), but not both.

Use label selectors effectively to filter large result sets. KubeArchive may contain extensive historical data, so targeted queries perform better than broad searches.

logs Command

Retrieve container logs from archived resources only. Unlike the get command which merges live and archived data, the logs command exclusively retrieves logs from the KubeArchive. The command supports direct pod logs and logs from resources that own pods (like deployments, jobs).

Pod Selection: When multiple pods match the search criteria (e.g., from deployments or label selectors), the command automatically selects the most recent pod.

Container Selection: If you do not specify a container with -c and the pod has multiple containers, the command may select a random container. Always specify the container name for predictable results.

Init Container Support: The command supports retrieving logs from init containers by specifying their names with the -c flag.

Syntax

kubectl ka logs ([RESOURCE[.VERSION[.GROUP]]/NAME] | [RESOURCE[.VERSION[.GROUP]]] | [NAME]) [flags]

Resource Specification

If the resource is not provided, the CLI assumes it is a Pod.

Options

Flag Description Default

--container, -c

Container name to retrieve logs from

(first container)

--namespace, -n

Kubernetes namespace to use for this request

(from kubeconfig)

--selector, -l

Label selector to filter resources

(none)

Examples

# Get logs from a pod
kubectl ka logs nginx-pod -c sidecar-container

# Get logs from deployment (picks one pod)
kubectl ka logs deployment/nginx

# Get logs from all pods matching label
kubectl ka logs pods -l app=nginx

config Command

Manage persistent configuration for different Kubernetes clusters. The plugin automatically stores cluster-specific KubeArchive settings, eliminating the need to specify connection details repeatedly.

For detailed configuration information, including environment variables, authentication methods, and certificate handling, see CLI Configuration.

Quick Start

# First time usage triggers automatic setup
kubectl ka get pods

# List configured clusters
kubectl ka config list

# Manual setup for current cluster
kubectl ka config setup

Subcommands

list

Display all configured clusters and their settings.

setup

Run interactive configuration setup for the current cluster.

set

Set individual configuration values (host, ca, insecure, token) for the current cluster.

unset

Clear/reset individual configuration values for the current cluster.

remove

Remove configuration for a specific cluster or the current cluster (--current).

See CLI Configuration for detailed examples, configuration file format, and advanced configuration options.

completion Command

Generate shell autocompletion scripts for bash, zsh, fish, or PowerShell. Autocompletion provides tab completion for commands and flags.

Autocompletion does not yet support resource names and types.

Syntax

kubectl ka completion [bash|zsh|fish|powershell]

Installation Examples

Bash

# Install completion for current session
source <(kubectl ka completion bash)

# Install completion permanently
kubectl ka completion bash > /etc/bash_completion.d/kubectl-ka

# Or for user-specific installation
kubectl ka completion bash > ~/.local/share/bash-completion/completions/kubectl-ka

Zsh

# Install completion for current session
source <(kubectl ka completion zsh)

# Install completion permanently
kubectl ka completion zsh > "${fpath[1]}/_kubectl-ka"

# Then reload your shell or run: autoload -U compinit; compinit

Fish

# Install completion for current session
kubectl ka completion fish | source

# Install completion permanently
kubectl ka completion fish > ~/.config/fish/completions/kubectl-ka.fish

PowerShell

# Install completion for current session
kubectl ka completion powershell | Out-String | Invoke-Expression

# Install completion permanently (add to PowerShell profile)
kubectl ka completion powershell >> $PROFILE