k8s v0.2.12 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(atom()) :: {: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", [user: "token-user"])
...> K8s.Cluster.register(:test_cluster, config_file)
...> {:ok, conf} = K8s.Cluster.conf(:test_cluster)
...> conf
%K8s.Conf{auth: %K8s.Conf.Auth.Token{token: "just-a-token-user-pun-intended"}, ca_cert: nil, cluster_name: "docker-for-desktop-cluster", insecure_skip_tls_verify: true, url: "https://localhost:6443",user_name: "token-user"}
Link to this function

list()
list() :: [atom()]

List registered cluster names

Link to this function

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

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(), atom()) ::
  {: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"}