hydrosdk.deployment_configuration module

class hydrosdk.deployment_configuration.Affinity(*, nodeAffinity=None, podAffinity=None, podAntiAffinity=None)

Bases: hydrosdk.deployment_configuration.K8SEntity

Group of affinity scheduling rules.

Parameters
Return type

None

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

class hydrosdk.deployment_configuration.ContainerSpec(*, resources=None, env=None)

Bases: hydrosdk.deployment_configuration.K8SEntity

ContainerSpec contains all configurations related to a container.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Parameters
Return type

None

class hydrosdk.deployment_configuration.DeploymentConfiguration(*, name, hpa=None, pod=None, container=None, deployment=None)

Bases: hydrosdk.deployment_configuration.K8SEntity

DeploymentConfiguration encapsulates k8s configs about how your Servables and ModelVariants should run.

Parameters
Return type

None

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

static delete(cluster, name)

Delete deployment configuration from Hydrosphere cluster

Parameters
Returns

json response from the server

Return type

dict

static find(cluster, name)

Search a deployment configuration by name

Parameters
Returns

Return type

hydrosdk.deployment_configuration.DeploymentConfiguration

static list(cluster)

List all deployment configurations

Parameters

cluster (hydrosdk.cluster.Cluster) –

Returns

Return type

List[hydrosdk.deployment_configuration.DeploymentConfiguration]

class hydrosdk.deployment_configuration.DeploymentConfigurationBuilder(name)

Bases: hydrosdk.builder.AbstractBuilder

DeploymentConfigBuilder is used to create a new DeploymentConfiguration.

Example

Parameters

name (str) –

Return type

DeploymentConfigurationBuilder

Create a new deployment configuration.

>>> from hydrosdk import Cluster, DeploymentConfigurationBuilder
>>> cluster = Cluster('http-cluster-endpoint')
>>> config_builder = DeploymentConfigurationBuilder(name="new_config")
>>> config = config_builder.with_hpa(max_replicas=10, min_replicas=2, target_cpu_utilization_percentage=80).                     with_pod_node_selector({"label1": "key1", "foo": "bar"}).                     with_resource_requirements(limits={"cpu": "4", "memory": "4G"},                                                requests={"cpu": "2", "memory": "2G"}).                     with_env({"ENVIRONMENT": "1"}).
                with_replicas(replica_count=4).                     with_toleration(effect="PreferNoSchedule", key="equalToleration", toleration_seconds=30, operator="Exists").                    build(cluster)

Create new Deployment Config Builder

Parameters

name (str) – Name of created deployment configuration

Return type

DeploymentConfigurationBuilder

build(cluster)

Create the Deployment Configuration in your Hydrosphere cluster.

Returns

Deployment Configuration object from the Hydrosphere cluster

Parameters

cluster (hydrosdk.cluster.Cluster) –

Return type

hydrosdk.deployment_configuration.DeploymentConfiguration

with_affinity(affinity)

Adds pod scheduling constraints

Parameters

affinity (hydrosdk.deployment_configuration.Affinity) – Group of affinity scheduling rules

Returns

Return type

hydrosdk.deployment_configuration.DeploymentConfigurationBuilder

with_env(env)

Specify env for the container.

Parameters

env (Dict[str, str]) – dictionary with the required environment variables.

Return type

hydrosdk.deployment_configuration.DeploymentConfigurationBuilder

with_hpa(max_replicas, min_replicas=1, target_cpu_utilization_percentage=None)

Adds a HorizontalPodAutoScaler specs to a DeploymentConfiguration.

Parameters
  • min_replicas – min_replicas is the lower limit for the number of replicas to which the autoscaler can scale down. It defaults to 1 pod. minReplicas is allowed to be 0 if the alpha feature gate HPAScaleToZero is enabled and at least one Object or External metric is configured. Scaling is active as long as at least one metric value is available.

  • max_replicas – upper limit for the number of pods that can be set by the autoscaler; cannot be smaller than MinReplicas.

  • target_cpu_utilization_percentage – target average CPU utilization (represented as a percentage of requested CPU) over all the pods; if not specified the default autoscaling policy will be used.

Return type

hydrosdk.deployment_configuration.DeploymentConfigurationBuilder

with_pod_node_selector(node_selector)

Adds selector which must be true for the pod to fit on a node.

Parameters

node_selector (Dict[str, str]) – Selector which must match a node’s labels for the pod to be scheduled on that node

Returns

Return type

hydrosdk.deployment_configuration.DeploymentConfigurationBuilder

with_replicas(replica_count=1)

Specify number of desired pods for a deployment

Parameters

replica_count – Number of desired pods. This is a pointer to distinguish between explicit zero and not specified. Defaults to 1.

Returns

Return type

hydrosdk.deployment_configuration.DeploymentConfigurationBuilder

with_resource_requirements(limits, requests=None)

Specify resources required by this container.

Parameters
  • limits (Dict[str, str]) – the maximum amount of compute resources allowed

  • requests (Optional[Dict[str, str]]) – Requests describes the minimum amount of compute resources required. If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, otherwise to an implementation-defined value.

Returns

Return type

hydrosdk.deployment_configuration.DeploymentConfigurationBuilder

with_toleration(effect=None, key=None, operator='Equal', toleration_seconds=None, value=None)
Specify pod’s toleration. The pod this Toleration is attached to tolerates any taint that matches the triple <key,value,effect>

using the matching operator <operator>.

Parameters
  • effect (Optional[str]) – Effect indicates the taint effect to match. Empty means match all taint effects. When specified, allowed values are NoSchedule, PreferNoSchedule and NoExecute.

  • key (Optional[str]) – Key is the taint key that the toleration applies to. Empty means match all taint keys. If the key is empty, operator must be Exists; this combination means to match all values and all keys.

  • operator (str) – Operator represents a key’s relationship to the value. Valid operators are Exists and Equal. Defaults to Equal. Exists is equivalent to wildcard for value, so that a pod can tolerate all taints of a particular category.

  • toleration_seconds (Optional[int]) – TolerationSeconds represents the period of time the toleration (which must be of effect NoExecute, otherwise this field is ignored) tolerates the taint. By default, it is not set, which means tolerate the taint forever (do not evict). Zero and negative values will be treated as 0 (evict immediately) by the system.

  • value (Optional[str]) – Value is the taint value the toleration matches to. If the operator is Exists, the value should be empty, otherwise just a regular string.

Return type

hydrosdk.deployment_configuration.DeploymentConfigurationBuilder

class hydrosdk.deployment_configuration.DeploymentSpec(*, replicaCount=1)

Bases: hydrosdk.deployment_configuration.K8SEntity

DeploymentSpec contains all configurations related to a deployment.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Parameters

replicaCount (int) –

Return type

None

class hydrosdk.deployment_configuration.HorizontalPodAutoScalerSpec(*, minReplicas, maxReplicas, cpuUtilization=None)

Bases: hydrosdk.deployment_configuration.K8SEntity

HPA Specification

Parameters
  • max_replicas – upper limit for the number of replicas to which the autoscaler can scale up. It cannot be less that minReplicas.

  • min_replicas – lower limit for the number of replicas to which the autoscaler can scale down. It defaults to 1 pod. minReplicas is allowed to be 0 if the alpha feature gate HPAScaleToZero is enabled and at least one Object or External metric is configured. Scaling is active as long as at least one metric value is available.

  • cpu_utilization – target average CPU utilization (represented as a percentage of requested CPU) over all the pods; if not specified the default autoscaling policy will be used.

  • minReplicas (int) –

  • maxReplicas (int) –

  • cpuUtilization (int) –

Return type

None

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

class hydrosdk.deployment_configuration.LabelSelector(*, matchExpressions=None, matchLabels=None)

Bases: hydrosdk.deployment_configuration.K8SEntity

A label selector is a label query over a set of resources. The result of matchLabels and matchExpressions are ANDed. An empty label selector matches all objects. A null label selector matches no objects.

Parameters
  • match_labels – map of {key,value} pairs. A single {key,value} in the matchLabels map is equivalent to an element of matchExpressions, whose key field is “key”, the operator is “In”, and the values array contains only “value”. The requirements are ANDed.

  • match_expressions – matchExpressions is a list of label selector requirements. The requirements are ANDed.

  • matchExpressions (List[hydrosdk.deployment_configuration.LabelSelectorRequirement]) –

  • matchLabels (Dict[str, str]) –

Return type

None

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

class hydrosdk.deployment_configuration.LabelSelectorRequirement(*, key, operator, values=None)

Bases: hydrosdk.deployment_configuration.K8SEntity

A label selector requirement is a selector that contains values, a key, and an operator that relates the key and values.

Parameters
  • key (str) – key is the label key that the selector applies to.

  • operator (str) – operator represents a key’s relationship to a set of values. Valid operators are In, NotIn, Exists and DoesNotExist.

  • values (Optional[List[str]]) – values is an array of string values. If the operator is In or NotIn, the values array must be non-empty. If the operator is Exists or DoesNotExist, the values array must be empty. This array is replaced during a strategic merge patch.

Return type

None

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

class hydrosdk.deployment_configuration.NodeAffinity(*, preferredDuringSchedulingIgnoredDuringExecution=[], requiredDuringSchedulingIgnoredDuringExecution=None)

Bases: hydrosdk.deployment_configuration.K8SEntity

Group of node affinity scheduling rules.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Parameters
Return type

None

class hydrosdk.deployment_configuration.NodeSelector(*, nodeSelectorTerms=[])

Bases: hydrosdk.deployment_configuration.K8SEntity

A node selector represents the union of the results of one or more label queries over a set of nodes; that is,

it represents the OR of the selectors represented by the node selector terms.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Parameters

nodeSelectorTerms (List[hydrosdk.deployment_configuration.NodeSelectorTerm]) –

Return type

None

class hydrosdk.deployment_configuration.NodeSelectorRequirement(*, key, operator, values=None)

Bases: hydrosdk.deployment_configuration.K8SEntity

A node selector requirement is a selector that contains values, a key, and an operator that relates the key and values.

Parameters
  • operator (str) – Represents a key’s relationship to a set of values. Valid operators are In, NotIn, Exists, DoesNotExist. Gt, and Lt.

  • key (str) – The label key that the selector applies to.

  • values (List[str]) – An array of string values. If the operator is In or NotIn, the values array must be non-empty. If the operator is Exists or DoesNotExist, the values array must be empty. If the operator is Gt or Lt, the values array must have a single element, which will be interpreted as an integer. This array is replaced during a strategic merge patch.

Return type

None

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

class hydrosdk.deployment_configuration.NodeSelectorTerm(*, matchExpressions=None, matchFields=None)

Bases: hydrosdk.deployment_configuration.K8SEntity

A null or empty node selector term matches no objects. The requirements of them are ANDed.

The TopologySelectorTerm type implements a subset of the NodeSelectorTerm.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Parameters
Return type

None

class hydrosdk.deployment_configuration.PodAffinity(*, preferredDuringSchedulingIgnoredDuringExecution=[], requiredDuringSchedulingIgnoredDuringExecution=[])

Bases: hydrosdk.deployment_configuration.K8SEntity

Pod affinity is a group of inter pod affinity scheduling rules.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Parameters
Return type

None

class hydrosdk.deployment_configuration.PodAffinityTerm(*, labelSelector, topologyKey, namespaces=None)

Bases: hydrosdk.deployment_configuration.K8SEntity

Defines a set of pods (namely those matching the labelSelector relative to the given namespace(s)) that this pod should be co-located (affinity) or not co-located (anti-affinity) with, where co-located is defined as running on a node whose value of the label with key <topologyKey> matches that of any node on which a pod of the set of pods is running

Parameters
  • label_selector – A label query over a set of resources, in this case pods.

  • namespaces (Optional[List[str]]) – namespaces specifies which namespaces the labelSelector applies to (matches against); null or empty list means “this pod’s namespace”

  • topology_key – This pod should be co-located (affinity) or not co-located (anti-affinity) with the pods matching the labelSelector in the specified namespaces, where co-located is defined as running on a node whose value of the label with key topologyKey matches that of any node on which any of the selected pods is running. Empty topologyKey is not allowed.

  • labelSelector (hydrosdk.deployment_configuration.LabelSelector) –

  • topologyKey (str) –

Return type

None

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

class hydrosdk.deployment_configuration.PodAntiAffinity(*, preferredDuringSchedulingIgnoredDuringExecution=[], requiredDuringSchedulingIgnoredDuringExecution=[])

Bases: hydrosdk.deployment_configuration.K8SEntity

Pod anti affinity is a group of inter pod anti affinity scheduling rules.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Parameters
Return type

None

class hydrosdk.deployment_configuration.PodSpec(*, nodeSelector={}, tolerations=[], affinity=None)

Bases: hydrosdk.deployment_configuration.K8SEntity

PodSpec contains all configurations related to a pod.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Parameters
Return type

None

class hydrosdk.deployment_configuration.PreferredSchedulingTerm(*, weight, preference)

Bases: hydrosdk.deployment_configuration.K8SEntity

An empty preferred scheduling term matches all objects with implicit weight 0 (i.e. it’s a no-op). A null preferred scheduling

term matches no objects (i.e. is also a no-op).

Parameters
Return type

None

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

class hydrosdk.deployment_configuration.ResourceRequirements(*, limits, requests=None)

Bases: hydrosdk.deployment_configuration.K8SEntity

Resources required by the container.

Parameters
  • limits (Dict[str, str]) – the maximum amount of compute resources allowed

  • requests (Dict[str, str]) – Requests describes the minimum amount of compute resources required. If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, otherwise to an implementation-defined value.

Return type

None

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

class hydrosdk.deployment_configuration.Toleration(*, operator, tolerationSeconds=None, key=None, value=None, effect=None)

Bases: hydrosdk.deployment_configuration.K8SEntity

The pod this Toleration is attached to tolerates any taint that matches the triple <key,value,effect> using the matching operator <operator>.

Parameters
  • effect (Optional[str]) – Effect indicates the taint effect to match. Empty means match all taint effects. When specified, allowed values are NoSchedule, PreferNoSchedule and NoExecute.

  • key (Optional[str]) – Key is the taint key that the toleration applies to. Empty means match all taint keys. If the key is empty, operator must be Exists; this combination means to match all values and all keys.

  • operator (str) – Operator represents a key’s relationship to the value. Valid operators are Exists and Equal. Defaults to Equal. Exists is equivalent to wildcard for value, so that a pod can tolerate all taints of a particular category.

  • toleration_seconds – TolerationSeconds represents the period of time the toleration (which must be of effect NoExecute, otherwise this field is ignored) tolerates the taint. By default, it is not set, which means tolerate the taint forever (do not evict). Zero and negative values will be treated as 0 (evict immediately) by the system.

  • value (Optional[str]) – Value is the taint value the toleration matches to. If the operator is Exists, the value should be empty, otherwise just a regular string.

  • tolerationSeconds (int) –

Return type

None

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

class hydrosdk.deployment_configuration.WeightedPodAffinityTerm(*, weight, podAffinityTerm)

Bases: hydrosdk.deployment_configuration.K8SEntity

The weights of all of the matched WeightedPodAffinityTerm fields are added per-node to find the most preferred node(s)

Parameters
  • pod_affinity_term – Required. A pod affinity term, associated with the corresponding weight.

  • weight (int) – weight associated with matching the corresponding podAffinityTerm, in the range 1-100.

  • podAffinityTerm (hydrosdk.deployment_configuration.PodAffinityTerm) –

Return type

None

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.