本文整理汇总了Python中kubernetes.client.V1DeploymentSpec方法的典型用法代码示例。如果您正苦于以下问题:Python client.V1DeploymentSpec方法的具体用法?Python client.V1DeploymentSpec怎么用?Python client.V1DeploymentSpec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kubernetes.client
的用法示例。
在下文中一共展示了client.V1DeploymentSpec方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sanitize_for_config_hash
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1DeploymentSpec [as 别名]
def test_sanitize_for_config_hash(self):
with mock.patch(
"paasta_tools.kubernetes_tools.get_kubernetes_secret_hashes", autospec=True
) as mock_get_kubernetes_secret_hashes:
mock_config = V1Deployment(
metadata=V1ObjectMeta(name="qwe", labels={"mc": "grindah"}),
spec=V1DeploymentSpec(
replicas=2,
selector=V1LabelSelector(match_labels={"freq": "108.9"}),
template=V1PodTemplateSpec(),
),
)
ret = self.deployment.sanitize_for_config_hash(mock_config)
assert "replicas" not in ret["spec"].keys()
assert (
ret["paasta_secrets"] == mock_get_kubernetes_secret_hashes.return_value
)
示例2: create_deployment
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1DeploymentSpec [as 别名]
def create_deployment(apps_v1_api):
container = client.V1Container(
name="deployment",
image="gcr.io/google-appengine/fluentd-logger",
image_pull_policy="Never",
ports=[client.V1ContainerPort(container_port=5678)],
)
# Template
template = client.V1PodTemplateSpec(
metadata=client.V1ObjectMeta(labels={"app": "deployment"}),
spec=client.V1PodSpec(containers=[container]))
# Spec
spec = client.V1DeploymentSpec(
replicas=1,
template=template)
# Deployment
deployment = client.V1Deployment(
api_version="apps/v1",
kind="Deployment",
metadata=client.V1ObjectMeta(name="deployment"),
spec=spec)
# Creation of the Deployment in specified namespace
# (Can replace "default" with a namespace you may have created)
apps_v1_api.create_namespaced_deployment(
namespace="default", body=deployment
)
示例3: create_deployment_object
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1DeploymentSpec [as 别名]
def create_deployment_object():
# Configureate Pod template container
container = client.V1Container(
name="nginx",
image="nginx:1.15.4",
ports=[client.V1ContainerPort(container_port=80)],
resources=client.V1ResourceRequirements(
requests={"cpu": "100m", "memory": "200Mi"},
limits={"cpu": "500m", "memory": "500Mi"}
)
)
# Create and configurate a spec section
template = client.V1PodTemplateSpec(
metadata=client.V1ObjectMeta(labels={"app": "nginx"}),
spec=client.V1PodSpec(containers=[container]))
# Create the specification of deployment
spec = client.V1DeploymentSpec(
replicas=3,
template=template,
selector={'matchLabels': {'app': 'nginx'}})
# Instantiate the deployment object
deployment = client.V1Deployment(
api_version="apps/v1",
kind="Deployment",
metadata=client.V1ObjectMeta(name=DEPLOYMENT_NAME),
spec=spec)
return deployment
示例4: deploy
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1DeploymentSpec [as 别名]
def deploy(self, image, name, ns, port, replicas=1, svc_type="NodePort", traffic_policy="Local", cluster_ip=None, ipv6=False):
"""
Creates a deployment and corresponding service with the given
parameters.
"""
# Run a deployment with <replicas> copies of <image>, with the
# pods labelled with "app": <name>.
deployment = client.V1Deployment(
api_version="apps/v1",
kind="Deployment",
metadata=client.V1ObjectMeta(name=name),
spec=client.V1DeploymentSpec(
replicas=replicas,
selector={'matchLabels': {'app': name}},
template=client.V1PodTemplateSpec(
metadata=client.V1ObjectMeta(labels={"app": name}),
spec=client.V1PodSpec(containers=[
client.V1Container(name=name,
image=image,
ports=[client.V1ContainerPort(container_port=port)]),
]))))
api_response = client.AppsV1Api().create_namespaced_deployment(
body=deployment,
namespace=ns)
logger.debug("Deployment created. status='%s'" % str(api_response.status))
# Create a service called <name> whose endpoints are the pods
# with "app": <name>; i.e. those just created above.
self.create_service(name, name, ns, port, svc_type, traffic_policy, ipv6=ipv6)
示例5: simple_deployment
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1DeploymentSpec [as 别名]
def simple_deployment():
"""Return the Kubernetes config matching the simple-deployment.yaml manifest."""
return client.V1Deployment(
api_version='apps/v1',
kind='Deployment',
metadata=client.V1ObjectMeta(
name='nginx-deployment',
labels={
'app': 'nginx'
}
),
spec=client.V1DeploymentSpec(
replicas=3,
selector=client.V1LabelSelector(
match_labels={
'app': 'nginx'
}
),
template=client.V1PodTemplateSpec(
metadata=client.V1ObjectMeta(
labels={
'app': 'nginx'
}
),
spec=client.V1PodSpec(
containers=[
client.V1Container(
name='nginx',
image='nginx:1.7.9',
ports=[
client.V1ContainerPort(
container_port=80
)
]
)
]
)
)
)
)
示例6: init_deployment
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1DeploymentSpec [as 别名]
def init_deployment(self, tosca_kube_obj, kube_obj_name):
"""Instantiate the deployment object"""
deployment_name = kube_obj_name
# Create a list of container, which made a Pod
containers = list()
for container_prop in tosca_kube_obj.containers:
limit_resource = self.init_resource_requirements(container_prop)
container = self.init_containers(
container_props=container_prop,
limit_resource=limit_resource,
name=deployment_name)
containers.append(container)
# Make a label with pattern {"selector": "deployment_name"}
if tosca_kube_obj.scaling_object:
scaling_name = tosca_kube_obj.scaling_object.scaling_name
update_label = self.config_labels(deployment_name=deployment_name,
scaling_name=scaling_name)
else:
update_label = self.config_labels(deployment_name=deployment_name)
if tosca_kube_obj.labels:
if 'selector' in update_label:
del update_label['selector']
update_label.update(tosca_kube_obj.labels)
labels = update_label
# Create and configure a spec section
pod_template = client.V1PodTemplateSpec(
metadata=client.V1ObjectMeta(
labels=labels, annotations=tosca_kube_obj.annotations),
spec=client.V1PodSpec(containers=containers))
# Create the specification of deployment
label_selector = client.V1LabelSelector(match_labels=labels)
deployment_spec = client.V1DeploymentSpec(
template=pod_template, selector=label_selector)
metadata = client.V1ObjectMeta(name=deployment_name, labels=labels)
# Instantiate the deployment object
deployment = client.V1Deployment(
api_version="apps/v1",
kind="Deployment",
metadata=metadata,
spec=deployment_spec)
return deployment
# init_hpa initializes Kubernetes Horizon Pod Auto-scaling object
示例7: __init__
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1DeploymentSpec [as 别名]
def __init__(self, name=None, selector=None, labels=None, image_metadata=None,
namespace='default', create_in_cluster=False, from_template=None):
"""
Utility functions for kubernetes deployments.
:param name: str, name of the deployment
:param selector: Label selector for pods. Existing ReplicaSets whose pods are selected by
this will be the ones affected by this deployment. It must match the pod template's labels
:param labels: dict, dict of labels
:param image_metadata: ImageMetadata
:param namespace: str, name of the namespace
:param create_in_cluster: bool, if True deployment is created in Kubernetes cluster
:param from_template: str, deployment template, example:
- https://kubernetes.io/docs/concepts/workloads/controllers/deployment/
"""
self.namespace = namespace
if (from_template is not None) and (name is not None or selector is not None or
labels is not None or image_metadata is not None):
raise ConuException(
'from_template cannot be passed to constructor at the same time with'
' name, selector, labels or image_metadata')
elif from_template is not None:
self.body = yaml.safe_load(from_template)
self.name = self.body['metadata']['name']
elif (name is not None and selector is not None and
labels is not None and image_metadata is not None):
self.name = name
self.pod = Pod.create(image_metadata)
self.spec = client.V1DeploymentSpec(
selector=client.V1LabelSelector(match_labels=selector),
template=client.V1PodTemplateSpec(metadata=client.V1ObjectMeta(labels=selector),
spec=self.pod.spec))
self.metadata = client.V1ObjectMeta(name=self.name, namespace=self.namespace,
labels=labels)
self.body = client.V1Deployment(spec=self.spec, metadata=self.metadata)
else:
raise ConuException(
'to create deployment you need to specify template or'
' properties: name, selector, labels, image_metadata')
self.api = get_apps_api()
if create_in_cluster:
self.create_in_cluster()