class Kubernetes::Resources::Pods

Overview

High-level API for Pod resources.

Provides type-safe methods for working with Pods without blocks, plus helpful utility methods like waiting for readiness and fetching logs.

Defined in:

resources/pods.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(client : Client) #

Instance Method Detail

def delete_namespaced(namespace : String, name : String) : Status #

Delete a pod.

Example:

status = k8s.v1.pods.delete_namespaced("default", "nginx-12345")

def exec(namespace : String, name : String, command : Array(String), container : String | Nil = nil) : String #

Execute a command in a pod (requires WebSocket support - planned for v1.0.0).

Example:

output = k8s.v1.pods.exec("default", "nginx", ["ls", "-la"])

def list_namespaced(namespace : String, label_selector : String | Nil = nil, field_selector : String | Nil = nil, limit : Int32 | Nil = nil) : List(Pod) #

List all pods in a namespace.

Example:

pods = k8s.v1.pods.list_namespaced("default")
pods.items.each { |pod| puts pod.metadata.name }

def logs(namespace : String, name : String, container : String | Nil = nil, follow : Bool = false, tail_lines : Int32 | Nil = nil) : String #

Get logs from a pod.

Example:

logs = k8s.v1.pods.logs("default", "nginx")
puts logs

# Get logs from specific container
logs = k8s.v1.pods.logs("default", "nginx", container: "app")

def paginate_namespaced(namespace : String, label_selector : String | Nil = nil, field_selector : String | Nil = nil, page_size : Int32 = 500, &) #

Paginate through all pods in a namespace.

Example:

k8s.v1.pods.paginate_namespaced("default", page_size: 100) do |pod|
  puts pod.metadata.name
end

def read_namespaced(namespace : String, name : String) : Pod #

Read a single pod.

Example:

pod = k8s.v1.pods.read_namespaced("default", "nginx-12345")
puts pod.status.try(&.phase)

def ready?(namespace : String, name : String) : Bool #

Check if a pod is ready.

Example:

if k8s.v1.pods.ready?("default", "nginx")
  puts "Pod is ready"
end

def running?(namespace : String, name : String) : Bool #

Check if a pod is running.

Example:

if k8s.v1.pods.running?("default", "nginx")
  puts "Pod is running"
end

def wait_until_ready(namespace : String, name : String, timeout = 5.minutes) : Pod #

Wait for a pod to be ready.

This method polls the pod status until all containers are ready or the timeout is reached.

Example:

pod = k8s.v1.pods.wait_until_ready("default", "nginx", timeout: 5.minutes)
puts "Pod is ready!"

def wait_until_running(namespace : String, name : String, timeout = 5.minutes) : Pod #

Wait for a pod to reach Running phase.

Example:

pod = k8s.v1.pods.wait_until_running("default", "nginx")

def watch_namespaced(namespace : String, resource_version = "0", timeout = 10.minutes, & : Watch(Pod) -> Nil) #

Watch pods for changes.

Example:

k8s.v1.pods.watch_namespaced("default") do |event|
  case event.type
  when .added? then puts "New pod: #{event.object.metadata.name}"
  end
end