Skip to content
Docs
Modules
kubernetes

kubernetes

ℹ️

This module requires that Risor has been compiled with the k8s Go build tag. When compiling manually, make sure you specify -tags k8s (opens in a new tab).

Module k8s provides methods for getting, listing, deleting and updating resources using the Kubernetes API.

Functions

get

Function signature
get(kind string, options object) object

Can be used to get a single object or a list of objects from the Kubernetes API.

Example
# get all namespaces
k8s.get("namespace.v1")
 
# get a specific namespace
k8s.get("namespace.v1", {"name": "default"})
 
# get pods by labels
k8s.get("pod.v1", {"namespace": "kube-system", "selector": "k8s-app=kube-apiserver" })
 
# get a specific pod by name
k8s.get("pod.v1", {"namespace": "kube-system", "name": "kube-apiserver-i-036c4abb51cd79a10"})
 
# get pods not running
k8s.get("pod.v1", {"fieldSelector": "status.phase!=Running"})

delete

Function signature
delete(kind string, options object) object

Can be used to delete a single object or a list of objects from the Kubernetes API.

Example
# delete pods not running
k8s.delete("pod.v1", {"fieldSelector": "status.phase!=Running"})

apply

Function signature
apply(manifest string, options object)

Can be used to apply (create or update) a kubernetes object from a JSON or YAML manifest

Example
manifest := string(os.read_file("/tmp/foo.yaml"))
apply(manifest, {"namespace": "my-namespace"})