salt.modules.k8s

Salt module to manage Kubernetes cluster

New in version 2016.3.0.

Roadmap:

  • Add creation of K8S objects (pod, rc, service, ...)
  • Add replace of K8S objects (pod, rc, service, ...)
  • Add deletion of K8S objects (pod, rc, service, ...)
  • Add rolling update
  • Add (auto)scalling
salt.modules.k8s.create_namespace(name, apiserver_url=None)

New in version 2016.3.0.

Create kubernetes namespace from the name, similar to the functionality added to kubectl since v.1.2.0: .. code-block:: bash

kubectl create namespaces namespace-name

CLI Example:

salt '*' k8s.create_namespace namespace_name

salt '*' k8s.create_namespace namespace_name http://kube-master.cluster.local
salt.modules.k8s.create_secret(namespace, name, sources, apiserver_url=None, force=False, update=False, saltenv=u'base')

New in version 2016.3.0.

Create k8s secrets in the defined namespace from the list of files

CLI Example:

salt '*' k8s.create_secret namespace_name secret_name sources

salt '*' k8s.create_secret namespace_name secret_name sources
http://kube-master.cluster.local

sources are either dictionary of {name: path, name1: path} pairs or array of strings defining paths.

Example of paths array:


['/full/path/filename', "file:///full/path/filename", "salt://secret/storage/file.txt", "http://user:password@securesite.com/secret-file.json"]

Example of dictionaries:


{"nameit": '/full/path/fiename', name2: "salt://secret/storage/file.txt"}

optional parameters accepted:

update=[false] default value is false if set to false, and secret is already present on the cluster - warning will be returned and no changes to the secret will be done. In case it is set to "true" and secret is present but data is differ - secret will be updated.

force=[true] default value is true if the to False, secret will not be created in case one of the files is not valid kubernetes secret. e.g. capital letters in secret name or _ in case force is set to True, wrong files will be skipped but secret will be created any way.

saltenv=['base'] default value is base in case 'salt://' path is used, this parameter can change the visibility of files

salt.modules.k8s.delete_secret(namespace, name, apiserver_url=None, force=True)

New in version 2016.3.0.

Delete kubernetes secret in the defined namespace. Namespace is the mandatory parameter as well as name.

CLI Example:

salt '*' k8s.delete_secret namespace_name secret_name

salt '*' k8s.delete_secret namespace_name secret_name http://kube-master.cluster.local
salt.modules.k8s.get_labels(node=None, apiserver_url=None)

New in version 2016.3.0.

Get labels from the current node

CLI Example:

salt '*' k8s.get_labels
salt '*' k8s.get_labels kube-node.cluster.local http://kube-master.cluster.local
salt.modules.k8s.get_namespaces(namespace=u'', apiserver_url=None)

New in version 2016.3.0.

Get one or all kubernetes namespaces.

If namespace parameter is omitted, all namespaces will be returned back to user, similar to following kubectl example:

kubectl get namespaces -o json

In case namespace is set by user, the output will be similar to the one from kubectl:

kubectl get namespaces namespace_name -o json

CLI Example:

salt '*' k8s.get_namespaces
salt '*' k8s.get_namespaces namespace_name http://kube-master.cluster.local
salt.modules.k8s.get_secrets(namespace, name=u'', apiserver_url=None, decode=False, brief=False)

Get k8s namespaces

CLI Example:

salt '*' k8s.get_secrets namespace_name
salt '*' k8s.get_secrets namespace_name secret_name http://kube-master.cluster.local
salt.modules.k8s.label_absent(name, node=None, apiserver_url=None)

New in version 2016.3.0.

Delete label to the current node

CLI Example:

salt '*' k8s.label_absent hw/disktype
salt '*' k8s.label_absent hw/disktype kube-node.cluster.local http://kube-master.cluster.local
salt.modules.k8s.label_folder_absent(name, node=None, apiserver_url=None)

New in version 2016.3.0.

Delete label folder to the current node

CLI Example:

salt '*' k8s.label_folder_absent hw
salt '*' k8s.label_folder_absent hw/ kube-node.cluster.local http://kube-master.cluster.local
salt.modules.k8s.label_present(name, value, node=None, apiserver_url=None)

New in version 2016.3.0.

Set label to the current node

CLI Example:

salt '*' k8s.label_present hw/disktype ssd

salt '*' k8s.label_present hw/disktype ssd kube-node.cluster.local http://kube-master.cluster.local
salt.modules.k8s.update_secret(namespace, name, sources, apiserver_url=None, force=True, saltenv=u'base')

New in version 2016.3.0.

alias to k8s.create_secret with update=true

CLI Example:

salt '*' k8s.update_secret namespace_name secret_name sources [apiserver_url] [force=true] [update=false] [saltenv='base']

sources are either dictionary of {name: path, name1: path} pairs or array of strings defining paths.

Example of paths array:


['/full/path/filename', "file:///full/path/filename", "salt://secret/storage/file.txt", "http://user:password@securesite.com/secret-file.json"]

Example of dictionaries:


{"nameit": '/full/path/fiename', name2: "salt://secret/storage/file.txt"}

optional parameters accepted:

force=[true] default value is true if the to False, secret will not be created in case one of the files is not valid kubernetes secret. e.g. capital letters in secret name or _ in case force is set to True, wrong files will be skipped but secret will be created any way.

saltenv=['base'] default value is base in case 'salt://' path is used, this parameter can change the visibility of files