salt.modules.kubernetesmod

Module for handling kubernetes calls.

optdepends:
  • kubernetes Python client < 4.0

  • PyYAML < 6.0

configuration:

The k8s API settings are provided either in a pillar, in the minion's config file, or in master's config file:

kubernetes.kubeconfig: '/path/to/kubeconfig'
kubernetes.kubeconfig-data: '<base64 encoded kubeconfig content'
kubernetes.context: 'context'

These settings can be overridden by adding context and `kubeconfig or kubeconfig_data parameters when calling a function.

The data format for kubernetes.kubeconfig-data value is the content of kubeconfig base64 encoded in one line.

Only kubeconfig or kubeconfig-data should be provided. In case both are provided kubeconfig entry is preferred.

CLI Example:

salt '*' kubernetes.nodes kubeconfig=/etc/salt/k8s/kubeconfig context=minikube

New in version 2017.7.0.

Changed in version 2019.2.0.

Warning

Configuration options changed in 2019.2.0. The following configuration options have been removed:

  • kubernetes.user

  • kubernetes.password

  • kubernetes.api_url

  • kubernetes.certificate-authority-data/file

  • kubernetes.client-certificate-data/file

  • kubernetes.client-key-data/file

Please use now:

  • kubernetes.kubeconfig or kubernetes.kubeconfig-data

  • kubernetes.context

salt.modules.kubernetesmod.configmaps(namespace='default', **kwargs)

Return a list of kubernetes configmaps defined in the namespace

CLI Example:

salt '*' kubernetes.configmaps
salt '*' kubernetes.configmaps namespace=default
salt.modules.kubernetesmod.create_configmap(name, namespace, data, source=None, template=None, saltenv='base', **kwargs)

Creates the kubernetes configmap as defined by the user.

CLI Example:

salt 'minion1' kubernetes.create_configmap             settings default '{"example.conf": "# example file"}'

salt 'minion2' kubernetes.create_configmap             name=settings namespace=default data='{"example.conf": "# example file"}'
salt.modules.kubernetesmod.create_deployment(name, namespace, metadata, spec, source, template, saltenv, **kwargs)

Creates the kubernetes deployment as defined by the user.

salt.modules.kubernetesmod.create_namespace(name, **kwargs)

Creates a namespace with the specified name.

CLI Example:

salt '*' kubernetes.create_namespace salt
salt '*' kubernetes.create_namespace name=salt
salt.modules.kubernetesmod.create_pod(name, namespace, metadata, spec, source, template, saltenv, **kwargs)

Creates the kubernetes deployment as defined by the user.

salt.modules.kubernetesmod.create_secret(name, namespace='default', data=None, source=None, template=None, saltenv='base', **kwargs)

Creates the kubernetes secret as defined by the user.

CLI Example:

salt 'minion1' kubernetes.create_secret             passwords default '{"db": "letmein"}'

salt 'minion2' kubernetes.create_secret             name=passwords namespace=default data='{"db": "letmein"}'
salt.modules.kubernetesmod.create_service(name, namespace, metadata, spec, source, template, saltenv, **kwargs)

Creates the kubernetes service as defined by the user.

salt.modules.kubernetesmod.delete_configmap(name, namespace='default', **kwargs)

Deletes the kubernetes configmap defined by name and namespace

CLI Example:

salt '*' kubernetes.delete_configmap settings default
salt '*' kubernetes.delete_configmap name=settings namespace=default
salt.modules.kubernetesmod.delete_deployment(name, namespace='default', **kwargs)

Deletes the kubernetes deployment defined by name and namespace

CLI Example:

salt '*' kubernetes.delete_deployment my-nginx
salt '*' kubernetes.delete_deployment name=my-nginx namespace=default
salt.modules.kubernetesmod.delete_namespace(name, **kwargs)

Deletes the kubernetes namespace defined by name

CLI Example:

salt '*' kubernetes.delete_namespace salt
salt '*' kubernetes.delete_namespace name=salt
salt.modules.kubernetesmod.delete_pod(name, namespace='default', **kwargs)

Deletes the kubernetes pod defined by name and namespace

CLI Example:

salt '*' kubernetes.delete_pod guestbook-708336848-5nl8c default
salt '*' kubernetes.delete_pod name=guestbook-708336848-5nl8c namespace=default
salt.modules.kubernetesmod.delete_secret(name, namespace='default', **kwargs)

Deletes the kubernetes secret defined by name and namespace

CLI Example:

salt '*' kubernetes.delete_secret confidential default
salt '*' kubernetes.delete_secret name=confidential namespace=default
salt.modules.kubernetesmod.delete_service(name, namespace='default', **kwargs)

Deletes the kubernetes service defined by name and namespace

CLI Example:

salt '*' kubernetes.delete_service my-nginx default
salt '*' kubernetes.delete_service name=my-nginx namespace=default
salt.modules.kubernetesmod.deployments(namespace='default', **kwargs)

Return a list of kubernetes deployments defined in the namespace

CLI Example:

salt '*' kubernetes.deployments
salt '*' kubernetes.deployments namespace=default
salt.modules.kubernetesmod.namespaces(**kwargs)

Return the names of the available namespaces

CLI Example:

salt '*' kubernetes.namespaces
salt '*' kubernetes.namespaces kubeconfig=/etc/salt/k8s/kubeconfig context=minikube
salt.modules.kubernetesmod.node(name, **kwargs)

Return the details of the node identified by the specified name

CLI Example:

salt '*' kubernetes.node name='minikube'
salt.modules.kubernetesmod.node_add_label(node_name, label_name, label_value, **kwargs)

Set the value of the label identified by label_name to label_value on the node identified by the name node_name. Creates the label if not present.

CLI Example:

salt '*' kubernetes.node_add_label node_name="minikube"             label_name="foo" label_value="bar"
salt.modules.kubernetesmod.node_labels(name, **kwargs)

Return the labels of the node identified by the specified name

CLI Example:

salt '*' kubernetes.node_labels name="minikube"
salt.modules.kubernetesmod.node_remove_label(node_name, label_name, **kwargs)

Removes the label identified by label_name from the node identified by the name node_name.

CLI Example:

salt '*' kubernetes.node_remove_label node_name="minikube"             label_name="foo"
salt.modules.kubernetesmod.nodes(**kwargs)

Return the names of the nodes composing the kubernetes cluster

CLI Example:

salt '*' kubernetes.nodes
salt '*' kubernetes.nodes kubeconfig=/etc/salt/k8s/kubeconfig context=minikube
salt.modules.kubernetesmod.ping(**kwargs)

Checks connections with the kubernetes API server. Returns True if the connection can be established, False otherwise.

CLI Example:

salt '*' kubernetes.ping
salt.modules.kubernetesmod.pods(namespace='default', **kwargs)

Return a list of kubernetes pods defined in the namespace

CLI Example:

salt '*' kubernetes.pods
salt '*' kubernetes.pods namespace=default
salt.modules.kubernetesmod.replace_configmap(name, data, source=None, template=None, saltenv='base', namespace='default', **kwargs)

Replaces an existing configmap with a new one defined by name and namespace with the specified data.

CLI Example:

salt 'minion1' kubernetes.replace_configmap             settings default '{"example.conf": "# example file"}'

salt 'minion2' kubernetes.replace_configmap             name=settings namespace=default data='{"example.conf": "# example file"}'
salt.modules.kubernetesmod.replace_deployment(name, metadata, spec, source, template, saltenv, namespace='default', **kwargs)

Replaces an existing deployment with a new one defined by name and namespace, having the specificed metadata and spec.

salt.modules.kubernetesmod.replace_secret(name, data, source=None, template=None, saltenv='base', namespace='default', **kwargs)

Replaces an existing secret with a new one defined by name and namespace, having the specificed data.

CLI Example:

salt 'minion1' kubernetes.replace_secret             name=passwords data='{"db": "letmein"}'

salt 'minion2' kubernetes.replace_secret             name=passwords namespace=saltstack data='{"db": "passw0rd"}'
salt.modules.kubernetesmod.replace_service(name, metadata, spec, source, template, old_service, saltenv, namespace='default', **kwargs)

Replaces an existing service with a new one defined by name and namespace, having the specificed metadata and spec.

salt.modules.kubernetesmod.secrets(namespace='default', **kwargs)

Return a list of kubernetes secrets defined in the namespace

CLI Example:

salt '*' kubernetes.secrets
salt '*' kubernetes.secrets namespace=default
salt.modules.kubernetesmod.services(namespace='default', **kwargs)

Return a list of kubernetes services defined in the namespace

CLI Example:

salt '*' kubernetes.services
salt '*' kubernetes.services namespace=default
salt.modules.kubernetesmod.show_configmap(name, namespace='default', **kwargs)

Return the kubernetes configmap defined by name and namespace.

CLI Example:

salt '*' kubernetes.show_configmap game-config default
salt '*' kubernetes.show_configmap name=game-config namespace=default
salt.modules.kubernetesmod.show_deployment(name, namespace='default', **kwargs)

Return the kubernetes deployment defined by name and namespace

CLI Example:

salt '*' kubernetes.show_deployment my-nginx default
salt '*' kubernetes.show_deployment name=my-nginx namespace=default
salt.modules.kubernetesmod.show_namespace(name, **kwargs)

Return information for a given namespace defined by the specified name

CLI Example:

salt '*' kubernetes.show_namespace kube-system
salt.modules.kubernetesmod.show_pod(name, namespace='default', **kwargs)

Return POD information for a given pod name defined in the namespace

CLI Example:

salt '*' kubernetes.show_pod guestbook-708336848-fqr2x
salt '*' kubernetes.show_pod guestbook-708336848-fqr2x namespace=default
salt.modules.kubernetesmod.show_secret(name, namespace='default', decode=False, **kwargs)

Return the kubernetes secret defined by name and namespace. The secrets can be decoded if specified by the user. Warning: this has security implications.

CLI Example:

salt '*' kubernetes.show_secret confidential default
salt '*' kubernetes.show_secret name=confidential namespace=default
salt '*' kubernetes.show_secret name=confidential decode=True
salt.modules.kubernetesmod.show_service(name, namespace='default', **kwargs)

Return the kubernetes service defined by name and namespace

CLI Example:

salt '*' kubernetes.show_service my-nginx default
salt '*' kubernetes.show_service name=my-nginx namespace=default