class

Kubernetes::Resources::Pods

Inherits Reference < Object

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.

Constructors

new(client : Client)
Source

Instance methods

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

Delete a pod.

Example:

status = k8s.v1.pods.delete_namespaced("default", "nginx-12345")
Source
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"])
Source
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 }
Source
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")
Source
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
Source
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)
Source
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
Source
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
Source
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!"
Source
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")
Source
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
Source

Nested types