k8s v0.2.5 K8s.Cluster

Cluster configuration and API route store for K8s.Client

Link to this section Summary

Functions

Retrieve a cluster's connection configuration.

List registered cluster names

Register a new cluster to use with K8s.Client

Registers clusters automatically from config.exs

Link to this section Functions

Link to this function

conf(cluster_name)
conf(binary()) :: {:ok, K8s.Conf.t()} | {:error, :cluster_not_registered}

Retrieve a cluster's connection configuration.

Example

iex> config_file = K8s.Conf.from_file("./test/support/kube-config.yaml")
...> K8s.Cluster.register("test-cluster", config_file)
...> {:ok, conf} = K8s.Cluster.conf("test-cluster")
...> conf
#Conf<%{cluster: "docker-for-desktop-cluster", user: "docker-for-desktop"}>
Link to this function

list()
list() :: [binary() | atom()]

List registered cluster names

Link to this function

register(cluster_name, conf)
register(binary(), K8s.Conf.t()) :: binary()

Register a new cluster to use with K8s.Client

Examples

iex> conf = K8s.Conf.from_file("./test/support/kube-config.yaml")
...> "test-cluster" = K8s.Cluster.register("test-cluster", conf)
"test-cluster"
Link to this function

register_clusters()

Registers clusters automatically from config.exs

Examples

By default a cluster will attempt to use the ServiceAccount assigned to the pod:

config :k8s,
  clusters: %{
    default: %{}
  }

Configuring a cluster using a k8s config:

config :k8s,
  clusters: %{
    default: %{
      conf: "~/.kube/config"
      conf_opts: [user: "some-user", cluster: "prod-cluster"]
    }
  }
Link to this function

url_for(operation, cluster_name)
url_for(K8s.Operation.t(), binary()) ::
  {:ok, binary()} | {:error, atom()} | {:error, binary()}

Retrieve the URL for a K8s.Operation

Examples

iex> conf = K8s.Conf.from_file("./test/support/kube-config.yaml")
...> K8s.Cluster.register("test-cluster", conf)
...> operation = K8s.Operation.build(:get, "apps/v1", :deployment, [namespace: "default", name: "nginx"])
...> K8s.Cluster.url_for(operation, "test-cluster")
{:ok, "https://localhost:6443/apis/apps/v1/namespaces/default/deployments/nginx"}