本文整理汇总了Python中kubernetes.client.V1ResourceRequirements方法的典型用法代码示例。如果您正苦于以下问题:Python client.V1ResourceRequirements方法的具体用法?Python client.V1ResourceRequirements怎么用?Python client.V1ResourceRequirements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kubernetes.client
的用法示例。
在下文中一共展示了client.V1ResourceRequirements方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _createKubePVC
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ResourceRequirements [as 别名]
def _createKubePVC(parser_args,CoreV1Api):
if parser_args.component=="search":
# {tenantName}-{environment}-search-master-gluster-volume
if parser_args.envtype == "auth":
_pvc_name=parser_args.tenant+parser_args.env+"-search-master-"+"volume"
elif parser_args.envtype == "live":
_pvc_name=parser_args.tenant+parser_args.env+"-search-repeater-"+"volume"
# Below config boby still need refine to accept more flexible extension
metadata = {'name': _pvc_name, 'namespace': parser_args.namespace}
requests = {'storage': parser_args.storage_size}
_V1ResourceRequirements=client.V1ResourceRequirements(requests=requests)
_V1PersistentVolumeClaimSpec=client.V1PersistentVolumeClaimSpec(resources=_V1ResourceRequirements,storage_class_name=parser_args.storage_class,access_modes=['ReadWriteMany'])
body = client.V1PersistentVolumeClaim(api_version='v1',kind='PersistentVolumeClaim', metadata=metadata,spec=_V1PersistentVolumeClaimSpec,) # V1PersistentVolumeClaim |
try:
api_response = CoreV1Api.create_namespaced_persistent_volume_claim(parser_args.namespace, body)
print(api_response)
except ApiException as e:
print("Exception when calling CoreV1Api->create_namespaced_persistent_volume_claim: %s\n" % e)
else:
print("Compoennt %s not need to create persistent volume chain on Kubernetes" %(parser_args.component))
示例2: simple_persistentvolumeclaim
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ResourceRequirements [as 别名]
def simple_persistentvolumeclaim():
"""Return the Kubernetes config matching the simple-persistentvolumeclaim.yaml manifest."""
return client.V1PersistentVolumeClaim(
api_version='v1',
kind='PersistentVolumeClaim',
metadata=client.V1ObjectMeta(
name='my-pvc'
),
spec=client.V1PersistentVolumeClaimSpec(
access_modes=[
'ReadWriteMany'
],
resources=client.V1ResourceRequirements(
requests={
'storage': '16Mi'
}
)
)
)
示例3: pod3
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ResourceRequirements [as 别名]
def pod3():
return V1Pod(
metadata=V1ObjectMeta(name='pod3', annotations=dict()),
status=V1PodStatus(
phase='Pending',
conditions=[
V1PodCondition(status='False', type='PodScheduled', reason='Unschedulable')
]
),
spec=V1PodSpec(
containers=[
V1Container(
name='container2',
resources=V1ResourceRequirements(requests={'cpu': '1.5'})
)
],
node_selector={'clusterman.com/pool': 'bar'}
)
)
示例4: pod5
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ResourceRequirements [as 别名]
def pod5():
return V1Pod(
metadata=V1ObjectMeta(name='pod5', annotations=dict()),
status=V1PodStatus(
phase='Pending',
conditions=None,
),
spec=V1PodSpec(
containers=[
V1Container(
name='container2',
resources=V1ResourceRequirements(requests={'cpu': '1.5'})
)
],
node_selector={'clusterman.com/pool': 'bar'}
)
)
示例5: create_deployment_object
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ResourceRequirements [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
示例6: get_resource_requirements
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ResourceRequirements [as 别名]
def get_resource_requirements(self) -> V1ResourceRequirements:
return V1ResourceRequirements(
limits={
"cpu": self.get_cpus() + self.get_cpu_burst_add(),
"memory": f"{self.get_mem()}Mi",
"ephemeral-storage": f"{self.get_disk()}Mi",
},
requests={
"cpu": self.get_cpus(),
"memory": f"{self.get_mem()}Mi",
"ephemeral-storage": f"{self.get_disk()}Mi",
},
)
示例7: get_sidecar_resource_requirements
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ResourceRequirements [as 别名]
def get_sidecar_resource_requirements(self) -> V1ResourceRequirements:
return V1ResourceRequirements(
limits={"cpu": 0.1, "memory": "1024Mi", "ephemeral-storage": "256Mi"},
requests={"cpu": 0.1, "memory": "1024Mi", "ephemeral-storage": "256Mi"},
)
示例8: get_volume_claim_templates
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ResourceRequirements [as 别名]
def get_volume_claim_templates(self) -> Sequence[V1PersistentVolumeClaim]:
return [
V1PersistentVolumeClaim(
metadata=V1ObjectMeta(name=self.get_persistent_volume_name(volume)),
spec=V1PersistentVolumeClaimSpec(
# must be ReadWriteOnce for EBS
access_modes=["ReadWriteOnce"],
storage_class_name=self.get_storage_class_name(volume),
resources=V1ResourceRequirements(
requests={"storage": f"{volume['size']}Gi"}
),
),
)
for volume in self.get_persistent_volumes()
]
示例9: get_kubernetes_resource_request
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ResourceRequirements [as 别名]
def get_kubernetes_resource_request(
resources: V1ResourceRequirements,
) -> Mapping[str, float]:
if not resources:
requests: Mapping[str, str] = {}
else:
requests = resources.requests or {}
parsed = kubernetes_tools.parse_container_resources(requests)
return {
"cpus": parsed.cpus,
"mem": parsed.mem,
"disk": parsed.disk,
}
示例10: test_get_resource_requirements
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ResourceRequirements [as 别名]
def test_get_resource_requirements(self):
with mock.patch(
"paasta_tools.kubernetes_tools.KubernetesDeploymentConfig.get_cpus",
autospec=True,
return_value=0.3,
), mock.patch(
"paasta_tools.kubernetes_tools.KubernetesDeploymentConfig.get_cpu_burst_add",
autospec=True,
return_value=1,
), mock.patch(
"paasta_tools.kubernetes_tools.KubernetesDeploymentConfig.get_mem",
autospec=True,
return_value=2048,
), mock.patch(
"paasta_tools.kubernetes_tools.KubernetesDeploymentConfig.get_disk",
autospec=True,
return_value=4096,
):
assert self.deployment.get_resource_requirements() == V1ResourceRequirements(
limits={"cpu": 1.3, "memory": "2048Mi", "ephemeral-storage": "4096Mi"},
requests={
"cpu": 0.3,
"memory": "2048Mi",
"ephemeral-storage": "4096Mi",
},
)
示例11: init_resource_requirements
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ResourceRequirements [as 别名]
def init_resource_requirements(self, container):
limits = dict()
requests = dict()
if container.num_cpus:
limits.update({'cpu': container.num_cpus})
requests.update({'cpu': container.num_cpus})
if container.mem_size:
limits.update({'memory': container.mem_size})
requests.update({'memory': container.mem_size})
return client.V1ResourceRequirements(limits=limits,
requests=requests)
示例12: pod1
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ResourceRequirements [as 别名]
def pod1():
return V1Pod(
metadata=V1ObjectMeta(name='pod1'),
status=V1PodStatus(phase='Running'),
spec=V1PodSpec(containers=[
V1Container(
name='container1',
resources=V1ResourceRequirements(requests={'cpu': '1.5'})
)
]
)
)
示例13: pod2
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ResourceRequirements [as 别名]
def pod2():
return V1Pod(
metadata=V1ObjectMeta(name='pod2', annotations={'clusterman.com/safe_to_evict': 'false'}),
status=V1PodStatus(phase='Running'),
spec=V1PodSpec(containers=[
V1Container(
name='container1',
resources=V1ResourceRequirements(requests={'cpu': '1.5'})
)
]
)
)
示例14: pod6
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ResourceRequirements [as 别名]
def pod6():
return V1Pod(
spec=V1PodSpec(
containers=[
V1Container(
name='container',
resources=V1ResourceRequirements(requests={'cpu': '1.5'})
)
],
affinity=V1Affinity(
node_affinity=V1NodeAffinity(
required_during_scheduling_ignored_during_execution=V1NodeSelector(
node_selector_terms=[
V1NodeSelectorTerm(
match_expressions=[
V1NodeSelectorRequirement(
key='clusterman.com/pool',
operator='In',
values=['bar']
)
]
)
]
)
)
)
)
)
示例15: test_calculate_resource_utilization_for_kube_nodes
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1ResourceRequirements [as 别名]
def test_calculate_resource_utilization_for_kube_nodes():
fake_nodes = [
V1Node(
metadata=V1ObjectMeta(name="fake_node1"),
status=V1NodeStatus(
allocatable={
"cpu": "500",
"ephemeral-storage": "200Mi",
"memory": "750Mi",
},
),
)
]
fake_pods_by_node = {
"fake_node1": [
V1Pod(
metadata=V1ObjectMeta(name="pod1"),
status=V1PodStatus(phase="Running"),
spec=V1PodSpec(
containers=[
V1Container(
name="container1",
resources=V1ResourceRequirements(
requests={
"cpu": "20",
"ephemeral-storage": "20Mi",
"memory": "20Mi",
}
),
)
]
),
)
]
}
free = metastatus_lib.calculate_resource_utilization_for_kube_nodes(
nodes=fake_nodes, pods_by_node=fake_pods_by_node
)["free"]
assert free.cpus == 480
assert free.mem == 730
assert free.disk == 180