turbot/kubernetes
steampipe plugin install kubernetes

Table: kubernetes_job - Query Kubernetes Jobs using SQL

Kubernetes Jobs are a resource that represent a finite task, i.e., they run until successful completion. They create one or more Pods and ensure that a specified number of them successfully terminate. As pods successfully complete, the job tracks the successful completions.

Table Usage Guide

The kubernetes_job table provides insights into Kubernetes Jobs within a Kubernetes cluster. As a DevOps engineer, explore job-specific details through this table, including the status of each job, the number of successful completions, and the parallelism limit. Utilize it to monitor the progress of jobs, ensure that they are running as expected, and troubleshoot any issues that occur.

Examples

Basic Info

Explore the status and performance of jobs within a Kubernetes environment. This allows users to assess job completion status, duration, and overall efficiency, aiding in system monitoring and optimization.

select
name,
namespace,
active,
succeeded,
failed,
completions,
start_time,
completion_time,
age(
coalesce(completion_time, current_timestamp),
start_time
) as duration,
active_deadline_seconds,
parallelism,
selector,
labels,
annotations
from
kubernetes_job;
select
name,
namespace,
active,
succeeded,
failed,
completions,
start_time,
completion_time,
strftime('%s', coalesce(completion_time, current_timestamp)) - strftime('%s', start_time) as duration,
active_deadline_seconds,
parallelism,
selector,
labels,
annotations
from
kubernetes_job;

List active jobs

Determine the areas in which jobs are currently active within a Kubernetes environment. This can be useful in managing resources and identifying any potential issues or bottlenecks.

select
name,
namespace,
start_time,
age(
coalesce(completion_time, current_timestamp),
start_time
) as duration,
active,
succeeded,
failed
from
kubernetes_job
where
active > 0;
select
name,
namespace,
start_time,
strftime('%s', coalesce(completion_time, current_timestamp)) - strftime('%s', start_time) as duration,
active,
succeeded,
failed
from
kubernetes_job
where
active > 0;

List failed jobs

Identify instances where jobs have failed in a Kubernetes environment. This enables quick detection of issues and facilitates timely troubleshooting.

select
name,
namespace,
start_time,
age(
coalesce(completion_time, current_timestamp),
start_time
) as duration,
active,
succeeded,
failed
from
kubernetes_job
where
failed > 0;
select
name,
namespace,
start_time,
coalesce(completion_time, datetime('now')) - start_time as duration,
active,
succeeded,
failed
from
kubernetes_job
where
failed > 0;

Get list of container and images for jobs

The query provides a way to identify the containers and images associated with specific jobs in a Kubernetes environment. This can be particularly useful for system administrators to track the resources being used by different jobs and ensure optimal resource allocation.

select
name,
namespace,
jsonb_agg(elems.value -> 'name') as containers,
jsonb_agg(elems.value -> 'image') as images
from
kubernetes_job,
jsonb_array_elements(template -> 'spec' -> 'containers') as elems
group by
name,
namespace;
select
name,
namespace,
json_group_array(json_extract(elems.value, '$.name')) as containers,
json_group_array(json_extract(elems.value, '$.image')) as images
from
kubernetes_job,
json_each(template, '$.spec.containers') as elems
group by
name,
namespace;

List manifest resources

Explore the status and details of active Kubernetes jobs, including their success and failure rates. This can be useful for identifying any jobs that may require attention or troubleshooting.

select
name,
namespace,
active,
succeeded,
failed,
completions,
parallelism,
selector,
labels,
annotations,
path
from
kubernetes_job
where
path is not null;
select
name,
namespace,
active,
succeeded,
failed,
completions,
parallelism,
selector,
labels,
annotations,
path
from
kubernetes_job
where
path is not null;

Control examples

Schema for kubernetes_job

NameTypeOperatorsDescription
_ctxjsonbSteampipe context in JSON form.
activebigintThe number of actively running pods.
active_deadline_secondsbigintThe duration in seconds relative to the startTime that the job may be active before the system tries to terminate it.
annotationsjsonbAnnotations is an unstructured key value map stored with a resource that may be set by external tools to store and retrieve arbitrary metadata.
backoff_limitbigintThe number of retries before marking this job failed. Defaults to 6.
completion_timetimestamp with time zoneTime when the job was completed.
completionsbigintThe desired number of successfully finished pods the job should be run with.
conditionsjsonbThe latest available observations of an object's current state.
context_nametextKubectl config context name.
creation_timestamptimestamp with time zoneCreationTimestamp is a timestamp representing the server time when this object was created.
deletion_grace_period_secondsbigintNumber of seconds allowed for this object to gracefully terminate before it will be removed from the system. Only set when deletionTimestamp is also set.
deletion_timestamptimestamp with time zoneDeletionTimestamp is RFC 3339 date and time at which this resource will be deleted.
end_linebigintThe path to the manifest file.
failedbigintThe number of pods which reached phase Failed.
finalizersjsonbMust be empty before the object is deleted from the registry. Each entry is an identifier for the responsible component that will remove the entry from the list. If the deletionTimestamp of the object is non-nil, entries in this list can only be removed.
generate_nametextGenerateName is an optional prefix, used by the server, to generate a unique name ONLY IF the Name field has not been provided.
generationbigintA sequence number representing a specific generation of the desired state.
labelsjsonbMap of string keys and values that can be used to organize and categorize (scope and select) objects. May match selectors of replication controllers and services.
manual_selectorbooleanManualSelector controls generation of pod labels and pod selectors. When false or unset, the system pick labels unique to this job and appends those labels to the pod template. When true, the user is responsible for picking unique labels and specifying the selector.
nametextName of the object. Name must be unique within a namespace.
namespacetextNamespace defines the space within which each name must be unique.
owner_referencesjsonbList of objects depended by this object. If ALL objects in the list have been deleted, this object will be garbage collected. If this object is managed by a controller, then an entry in this list will point to this controller, with the controller field set to true. There cannot be more than one managing controller.
parallelismbigintThe maximum desired number of pods the job should run at any given time. The actual number of pods running in steady state will be less than this number when ((.spec.completions - .status.successful) < .spec.parallelism), i.e. when the work left to do is less than max parallelism.
pathtextThe path to the manifest file.
resource_versiontextAn opaque value that represents the internal version of this object that can be used by clients to determine when objects have changed.
selectorjsonbA label query over pods that should match the pod count.
selector_querytextA query string representation of the selector.
source_typetextThe source of the resource. Possible values are: deployed and manifest. If the resource is fetched from the spec file the value will be manifest.
sp_connection_nametextSteampipe connection name.
sp_ctxjsonbSteampipe context in JSON form.
start_linebigintThe path to the manifest file.
start_timetimestamp with time zoneTime when the job was acknowledged by the job controller.
succeededbigintThe number of pods which reached phase Succeeded.
tagsjsonbA map of tags for the resource. This includes both labels and annotations.
templatejsonbDescribes the pod that will be created when executing a job.
titletextTitle of the resource.
ttl_seconds_after_finishedbigintlimits the lifetime of a Job that has finished execution (either Complete or Failed). If this field is set, ttlSecondsAfterFinished after the Job finishes, it is eligible to be automatically deleted.
uidtextUID is the unique in time and space value for this object.

Export

This table is available as a standalone Exporter CLI. Steampipe exporters are stand-alone binaries that allow you to extract data using Steampipe plugins without a database.

You can download the tarball for your platform from the Releases page, but it is simplest to install them with the steampipe_export_installer.sh script:

/bin/sh -c "$(curl -fsSL https://steampipe.io/install/export.sh)" -- kubernetes

You can pass the configuration to the command with the --config argument:

steampipe_export_kubernetes --config '<your_config>' kubernetes_job