kubernetes

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

Added 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

saltext.kubernetes.modules.kubernetesmod.__virtual__()[source]

Check dependencies

saltext.kubernetes.modules.kubernetesmod.ping(**kwargs)[source]

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

CLI Example:

salt '*' kubernetes.ping
saltext.kubernetes.modules.kubernetesmod.nodes(**kwargs)[source]

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
saltext.kubernetes.modules.kubernetesmod.node(name, **kwargs)[source]

Return the details of the node identified by the specified name

CLI Example:

salt '*' kubernetes.node name='minikube'
saltext.kubernetes.modules.kubernetesmod.node_labels(name, **kwargs)[source]

Return the labels of the node identified by the specified name

CLI Example:

salt '*' kubernetes.node_labels name="minikube"
saltext.kubernetes.modules.kubernetesmod.node_add_label(node_name, label_name, label_value, **kwargs)[source]

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"
saltext.kubernetes.modules.kubernetesmod.node_remove_label(node_name, label_name, **kwargs)[source]

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"
saltext.kubernetes.modules.kubernetesmod.namespaces(**kwargs)[source]

Return the names of the available namespaces

CLI Example:

salt '*' kubernetes.namespaces
salt '*' kubernetes.namespaces kubeconfig=/etc/salt/k8s/kubeconfig context=minikube
saltext.kubernetes.modules.kubernetesmod.deployments(namespace='default', **kwargs)[source]

Return a list of kubernetes deployments defined in the namespace

CLI Example:

salt '*' kubernetes.deployments
salt '*' kubernetes.deployments namespace=default
saltext.kubernetes.modules.kubernetesmod.services(namespace='default', **kwargs)[source]

Return a list of kubernetes services defined in the namespace

CLI Example:

salt '*' kubernetes.services
salt '*' kubernetes.services namespace=default
saltext.kubernetes.modules.kubernetesmod.pods(namespace='default', **kwargs)[source]

Return a list of kubernetes pods defined in the namespace

CLI Example:

salt '*' kubernetes.pods
salt '*' kubernetes.pods namespace=default
saltext.kubernetes.modules.kubernetesmod.secrets(namespace='default', **kwargs)[source]

Return a list of kubernetes secrets defined in the namespace

CLI Example:

salt '*' kubernetes.secrets
salt '*' kubernetes.secrets namespace=default
saltext.kubernetes.modules.kubernetesmod.configmaps(namespace='default', **kwargs)[source]

Return a list of kubernetes configmaps defined in the namespace

CLI Example:

salt '*' kubernetes.configmaps
salt '*' kubernetes.configmaps namespace=default
saltext.kubernetes.modules.kubernetesmod.show_deployment(name, namespace='default', **kwargs)[source]

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
saltext.kubernetes.modules.kubernetesmod.show_service(name, namespace='default', **kwargs)[source]

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
saltext.kubernetes.modules.kubernetesmod.show_pod(name, namespace='default', **kwargs)[source]

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
saltext.kubernetes.modules.kubernetesmod.show_namespace(name, **kwargs)[source]

Return information for a given namespace defined by the specified name

CLI Example:

salt '*' kubernetes.show_namespace kube-system
saltext.kubernetes.modules.kubernetesmod.show_secret(name, namespace='default', decode=False, **kwargs)[source]

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
saltext.kubernetes.modules.kubernetesmod.show_configmap(name, namespace='default', **kwargs)[source]

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
saltext.kubernetes.modules.kubernetesmod.delete_deployment(name, namespace='default', **kwargs)[source]

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
saltext.kubernetes.modules.kubernetesmod.delete_service(name, namespace='default', **kwargs)[source]

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
saltext.kubernetes.modules.kubernetesmod.delete_pod(name, namespace='default', **kwargs)[source]

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
saltext.kubernetes.modules.kubernetesmod.delete_namespace(name, **kwargs)[source]

Deletes the kubernetes namespace defined by name

CLI Example:

salt '*' kubernetes.delete_namespace salt
salt '*' kubernetes.delete_namespace name=salt
saltext.kubernetes.modules.kubernetesmod.delete_secret(name, namespace='default', **kwargs)[source]

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
saltext.kubernetes.modules.kubernetesmod.delete_configmap(name, namespace='default', **kwargs)[source]

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
saltext.kubernetes.modules.kubernetesmod.create_deployment(name, namespace, metadata, spec, source, template, saltenv, **kwargs)[source]

Creates the kubernetes deployment as defined by the user.

CLI Example:

salt '*' kubernetes.create_deployment *args
saltext.kubernetes.modules.kubernetesmod.create_pod(name, namespace, metadata, spec, source, template, saltenv, **kwargs)[source]

Creates the kubernetes deployment as defined by the user.

CLI Example:

salt '*' kubernetes.create_pod *args
saltext.kubernetes.modules.kubernetesmod.create_service(name, namespace, metadata, spec, source, template, saltenv, **kwargs)[source]

Creates the kubernetes service as defined by the user.

CLI Example:

salt '*' kubernetes.create_service *args
saltext.kubernetes.modules.kubernetesmod.create_secret(name, namespace='default', data=None, source=None, template=None, saltenv='base', **kwargs)[source]

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"}'
saltext.kubernetes.modules.kubernetesmod.create_configmap(name, namespace, data, source=None, template=None, saltenv='base', **kwargs)[source]

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"}'
saltext.kubernetes.modules.kubernetesmod.create_namespace(name, **kwargs)[source]

Creates a namespace with the specified name.

CLI Example:

salt '*' kubernetes.create_namespace salt
salt '*' kubernetes.create_namespace name=salt
saltext.kubernetes.modules.kubernetesmod.replace_deployment(name, metadata, spec, source, template, saltenv, namespace='default', **kwargs)[source]

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

CLI Example:

salt '*' kubernetes.replace_deployment *args
saltext.kubernetes.modules.kubernetesmod.replace_service(name, metadata, spec, source, template, old_service, saltenv, namespace='default', **kwargs)[source]

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

CLI Example:

salt '*' kubernetes.replace_service *args
saltext.kubernetes.modules.kubernetesmod.replace_secret(name, data, source=None, template=None, saltenv='base', namespace='default', **kwargs)[source]

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"}'
saltext.kubernetes.modules.kubernetesmod.replace_configmap(name, data, source=None, template=None, saltenv='base', namespace='default', **kwargs)[source]

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"}'