or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

api-clients.mdconfiguration.mdindex.mdmonitoring.mdpod-operations.mdutilities.md
tile.json

tessl/npm-kubernetes--client-node

Comprehensive Node.js client library for interacting with Kubernetes clusters with full API coverage and TypeScript support

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@kubernetes/client-node@1.3.x

To install, run

npx @tessl/cli install tessl/npm-kubernetes--client-node@1.3.0

index.mddocs/

Kubernetes Client Node

The Kubernetes Client Node library provides a comprehensive TypeScript/JavaScript client for interacting with Kubernetes clusters from Node.js applications. It offers complete Kubernetes API coverage through auto-generated client code, high-level convenience classes for common operations, and robust authentication support for various cloud providers.

Package Information

  • Package Name: @kubernetes/client-node
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @kubernetes/client-node

Core Imports

import { 
  KubeConfig, 
  CoreV1Api, 
  AppsV1Api,
  Watch,
  Log,
  Exec,
  Attach,
  PortForward,
  Metrics
} from '@kubernetes/client-node';

For CommonJS:

const { 
  KubeConfig, 
  CoreV1Api, 
  AppsV1Api,
  Watch,
  Log,
  Exec,
  Attach,
  PortForward,
  Metrics
} = require('@kubernetes/client-node');

Basic Usage

import { KubeConfig, CoreV1Api } from '@kubernetes/client-node';

// Load configuration
const kc = new KubeConfig();
kc.loadFromDefault();

// Create API client
const k8sApi = kc.makeApiClient(CoreV1Api);

// List pods in default namespace
try {
  const res = await k8sApi.listNamespacedPod('default');
  console.log('Found pods:', res.body.items.map(pod => pod.metadata?.name));
} catch (err) {
  console.error('Error:', err);
}

Architecture

The Kubernetes Client Node library is organized around several key components:

  • Configuration System: KubeConfig class handles cluster connection, authentication, and context management
  • Generated API Clients: Complete coverage of all Kubernetes API groups with type-safe methods
  • High-Level Operations: Convenience classes for common tasks like exec, attach, port forwarding, and log streaming
  • Monitoring Tools: Watch, Informer, and Metrics classes for real-time cluster observation
  • Authentication Providers: Support for various auth methods including OIDC, Azure AD, Google Cloud, and more
  • Utilities: YAML processing, health checking, caching, and object management tools

Capabilities

Configuration and Authentication

Core configuration management and authentication for Kubernetes cluster access. Supports multiple authentication methods and flexible configuration loading.

class KubeConfig {
  loadFromDefault(options?: ConfigOptions): void;
  loadFromFile(file: string): void;
  loadFromString(config: string): void;
  loadFromCluster(): void;
  makeApiClient<T>(apiClientType: ApiType<T>): T;
}

Configuration and Authentication

Generated API Clients

Complete Kubernetes API coverage with type-safe client classes for all API groups. Provides full CRUD operations for all Kubernetes resources.

class CoreV1Api {
  listNamespacedPod(namespace: string, options?: object): Promise<KubernetesListObject<V1Pod>>;
  createNamespacedPod(namespace: string, body: V1Pod, options?: object): Promise<V1Pod>;
  deleteNamespacedPod(name: string, namespace: string, options?: object): Promise<V1Status>;
}

class AppsV1Api {
  listNamespacedDeployment(namespace: string, options?: object): Promise<KubernetesListObject<V1Deployment>>;
  createNamespacedDeployment(namespace: string, body: V1Deployment, options?: object): Promise<V1Deployment>;
}

Generated API Clients

Pod Operations

High-level classes for interactive pod operations including command execution, container attachment, port forwarding, and file transfer.

class Exec {
  exec(
    namespace: string,
    podName: string,
    containerName: string,
    command: string | string[],
    stdout: stream.Writable | null,
    stderr: stream.Writable | null,
    stdin: stream.Readable | null,
    tty: boolean,
    statusCallback?: (status: V1Status) => void
  ): Promise<WebSocket.WebSocket>;
}

class PortForward {
  portForward(
    namespace: string,
    podName: string,
    targetPorts: number[],
    output: stream.Writable,
    err: stream.Writable | null,
    input: stream.Readable,
    retryCount?: number
  ): Promise<WebSocket.WebSocket | (() => WebSocket.WebSocket | null)>;
}

Pod Operations

Monitoring and Observability

Real-time monitoring tools for watching resource changes, streaming logs, collecting metrics, and implementing the informer pattern for efficient resource caching.

class Watch {
  watch(
    path: string,
    queryParams: Record<string, string | number | boolean | undefined>,
    callback: (phase: string, apiObj: any, watchObj?: any) => void,
    done: (err: any) => void
  ): Promise<AbortController>;
}

class Log {
  log(
    namespace: string,
    podName: string,
    containerName: string,
    stream: Writable,
    options?: LogOptions
  ): Promise<AbortController>;
}

class Metrics {
  getNodeMetrics(): Promise<NodeMetricsList>;
  getPodMetrics(namespace?: string): Promise<PodMetricsList>;
}

Monitoring and Observability

Object Management and Utilities

Generic object management, YAML processing, health checking, and utility functions for working with Kubernetes resources and cluster operations.

class KubernetesObjectApi {
  static makeApiClient(kc: KubeConfig): KubernetesObjectApi;
  create(obj: KubernetesObject, options?: object): Promise<KubernetesObject>;
  delete(obj: KubernetesObject, options?: object): Promise<V1Status>;
  read(obj: KubernetesObject): Promise<KubernetesObject>;
  patch(obj: KubernetesObject, patch: object, options?: object): Promise<KubernetesObject>;
  replace(obj: KubernetesObject, options?: object): Promise<KubernetesObject>;
}

function loadYaml<T>(data: string, opts?: yaml.LoadOptions): T;
function dumpYaml(object: any, opts?: yaml.DumpOptions): string;

Object Management and Utilities

Types

interface KubernetesObject {
  apiVersion?: string;
  kind?: string;
  metadata?: V1ObjectMeta;
}

interface KubernetesListObject<T> {
  apiVersion?: string;
  kind?: string;
  metadata?: V1ListMeta;
  items: T[];
}

interface ConfigOptions {
  onInvalidEntry?: ActionOnInvalid;
}

interface LogOptions {
  follow?: boolean;
  limitBytes?: number;
  pretty?: boolean;
  previous?: boolean;
  sinceSeconds?: number;
  sinceTime?: string;
  tailLines?: number;
  timestamps?: boolean;
}

type IntOrString = number | string;

interface ApiType<T = any> {
  new(config?: Configuration): T;
}

type KubernetesApiAction = 'create' | 'delete' | 'patch' | 'read' | 'list' | 'replace';

interface RequestOptions {
  /** Request timeout in milliseconds */
  timeout?: number;
  /** Additional headers */
  headers?: Record<string, string>;
}

interface ConfigurationOptions {
  /** Base path for API requests */
  basePath?: string;
  /** HTTP timeout in milliseconds */
  timeout?: number;
  /** Additional headers */
  headers?: Record<string, string>;
  /** Request middleware */
  middleware?: any[];
}

interface ApiException extends Error {
  /** HTTP status code */
  code?: number;
  /** Response body */
  body?: any;
  /** Response headers */
  headers?: any;
}