当前位置: 首页>>代码示例>>Python>>正文


Python client.V1PodSpec方法代码示例

本文整理汇总了Python中kubernetes.client.V1PodSpec方法的典型用法代码示例。如果您正苦于以下问题:Python client.V1PodSpec方法的具体用法?Python client.V1PodSpec怎么用?Python client.V1PodSpec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kubernetes.client的用法示例。


在下文中一共展示了client.V1PodSpec方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_job_manifest

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1PodSpec [as 别名]
def create_job_manifest(envs, commands, name, image, template_file):
    if template_file is not None:
        with open( template_file ) as f:
            job=yaml.safe_load(f)
            job["metadata"]["name"]=name
            job["spec"]["template"]["metadata"]["labels"]["app"]=name
            job["spec"]["template"]["spec"]["containers"][0]["image"]=image
            job["spec"]["template"]["spec"]["containers"][0]["command"]=commands
            job["spec"]["template"]["spec"]["containers"][0]["name"]=name
            job["spec"]["template"]["spec"]["containers"][0]["env"]=envs
            job["spec"]["template"]["spec"]["containers"][0]["command"]=commands
    else:
        container=client.V1Container(image=image, command=commands, name=name, env=envs)
        pod_temp=client.V1PodTemplateSpec(
                spec=client.V1PodSpec(restart_policy="OnFailure", containers=[container]),
                metadata=client.V1ObjectMeta(name=name, labels={"app":name})
                )
        job=client.V1Job(
                api_version="batch/v1",
                kind="Job",
                spec=client.V1JobSpec(template=pod_temp),
                metadata=client.V1ObjectMeta(name=name)
                )
    return job 
开发者ID:mlperf,项目名称:training_results_v0.6,代码行数:26,代码来源:kubernetes.py

示例2: create_job_object

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1PodSpec [as 别名]
def create_job_object():
    # Configureate Pod template container
    container = client.V1Container(
        name="pi",
        image="perl",
        command=["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"])
    # Create and configurate a spec section
    template = client.V1PodTemplateSpec(
        metadata=client.V1ObjectMeta(labels={"app": "pi"}),
        spec=client.V1PodSpec(restart_policy="Never", containers=[container]))
    # Create the specification of deployment
    spec = client.V1JobSpec(
        template=template,
        backoff_limit=4)
    # Instantiate the job object
    job = client.V1Job(
        api_version="batch/v1",
        kind="Job",
        metadata=client.V1ObjectMeta(name=JOB_NAME),
        spec=spec)

    return job 
开发者ID:kubernetes-client,项目名称:python,代码行数:24,代码来源:job_crud.py

示例3: _create_k8s_job

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1PodSpec [as 别名]
def _create_k8s_job(self, yaml_spec):
    """ _create_k8s_job creates a kubernetes job based on the yaml spec """
    pod = k8s_client.V1Pod(metadata=k8s_client.V1ObjectMeta(generate_name=yaml_spec['metadata']['generateName'],
                                                            annotations=yaml_spec['metadata']['annotations']))
    container = k8s_client.V1Container(name = yaml_spec['spec']['containers'][0]['name'],
                                       image = yaml_spec['spec']['containers'][0]['image'],
                                       args = yaml_spec['spec']['containers'][0]['args'])
    pod.spec = k8s_client.V1PodSpec(restart_policy=yaml_spec['spec']['restartPolicy'],
                                    containers = [container],
                                    service_account_name=yaml_spec['spec']['serviceAccountName'])
    try:
      api_response = self._corev1.create_namespaced_pod(yaml_spec['metadata']['namespace'], pod)
      return api_response.metadata.name, True
    except k8s_client.rest.ApiException as e:
      logging.exception("Exception when calling CoreV1Api->create_namespaced_pod: {}\n".format(str(e)))
      return '', False 
开发者ID:kubeflow,项目名称:pipelines,代码行数:18,代码来源:_k8s_job_helper.py

示例4: pod3

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1PodSpec [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'}
        )
    ) 
开发者ID:Yelp,项目名称:clusterman,代码行数:21,代码来源:kubernetes_cluster_connector_test.py

示例5: pod5

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1PodSpec [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'}
        )
    ) 
开发者ID:Yelp,项目名称:clusterman,代码行数:19,代码来源:kubernetes_cluster_connector_test.py

示例6: create_deployment

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1PodSpec [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
    ) 
开发者ID:kubernetes-client,项目名称:python,代码行数:28,代码来源:ingress_create.py

示例7: create_deployment_object

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1PodSpec [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 
开发者ID:kubernetes-client,项目名称:python,代码行数:30,代码来源:deployment_crud.py

示例8: create_job_object

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1PodSpec [as 别名]
def create_job_object(runner_image, region, s3_path, pvc_name):
  target_folder = get_target_folder(s3_path)

  # Configureate Pod template container
  container = k8s_client.V1Container(
      name="copy-dataset-worker",
      image=runner_image,
      command=["aws"],
      args=["s3", "sync", s3_path, "/mnt/" + target_folder],
      volume_mounts=[k8s_client.V1VolumeMount(name="data-storage", mount_path='/mnt')],
      env=[k8s_client.V1EnvVar(name="AWS_REGION", value=region),
        k8s_client.V1EnvVar(name="AWS_ACCESS_KEY_ID", value_from=k8s_client.V1EnvVarSource(secret_key_ref=k8s_client.V1SecretKeySelector(key="AWS_ACCESS_KEY_ID", name="aws-secret"))),
        k8s_client.V1EnvVar(name="AWS_SECRET_ACCESS_KEY", value_from=k8s_client.V1EnvVarSource(secret_key_ref=k8s_client.V1SecretKeySelector(key="AWS_SECRET_ACCESS_KEY", name="aws-secret")))
        ],
    )
  volume = k8s_client.V1Volume(
    name='data-storage',
    persistent_volume_claim=k8s_client.V1PersistentVolumeClaimVolumeSource(claim_name=pvc_name)
  )
  # Create and configurate a spec section
  template = k8s_client.V1PodTemplateSpec(
      # metadata=k8s_client.V1ObjectMeta(labels={"app":"copy-dataset-worker"}),
      spec=k8s_client.V1PodSpec(containers=[container], volumes=[volume], restart_policy="OnFailure"))
  # Create the specification of deployment
  spec = k8s_client.V1JobSpec(
      # selector=k8s_client.V1LabelSelector(match_labels={"app":"copy-dataset-worker"}),
      template=template)
  # Instantiate the deployment object
  deployment = k8s_client.V1Job(
      api_version="batch/v1",
      kind="Job",
      metadata=k8s_client.V1ObjectMeta(name=container.name),
      spec=spec)

  return deployment 
开发者ID:aws-samples,项目名称:aws-eks-deep-learning-benchmark,代码行数:37,代码来源:copy_dataset.py

示例9: test_clusterinit_update_pod_with_init_container

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1PodSpec [as 别名]
def test_clusterinit_update_pod_with_init_container():
    pod_passed = k8sclient.V1Pod(
        metadata=k8sclient.V1ObjectMeta(annotations={}),
        spec=k8sclient.V1PodSpec(containers=[
            k8sclient.V1Container(name="cmk")
        ]),
        status=k8sclient.V1PodStatus()).to_dict()
    cmd = "cmd"
    cmk_img = "cmk_img"
    cmk_img_pol = "policy"
    args = "argument"
    clusterinit.update_pod_with_init_container(pod_passed, cmd, cmk_img,
                                               cmk_img_pol,
                                               args)
    pods = json.loads(pod_passed["metadata"]["annotations"][
                          "pod.beta.kubernetes.io/init-containers"])
    assert len(pods) == 1
    assert pods[0]["name"] == cmd
    assert pods[0]["image"] == cmk_img
    assert pods[0]["imagePullPolicy"] == cmk_img_pol
    assert args in pods[0]["args"]

    second_cmd = "cmd2"
    second_img = cmk_img
    second_img_pol = "Always"
    second_args = ["arg1", "arg2"]
    clusterinit.update_pod_with_init_container(pod_passed, second_cmd,
                                               second_img,
                                               second_img_pol,
                                               second_args)

    pods = json.loads(pod_passed["metadata"]["annotations"][
                          "pod.beta.kubernetes.io/init-containers"])
    assert len(pods) == 2 
开发者ID:intel,项目名称:CPU-Manager-for-Kubernetes,代码行数:36,代码来源:test_clusterinit.py

示例10: _mock_launcher_pod

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1PodSpec [as 别名]
def _mock_launcher_pod(self):
    return client.V1Pod(
        metadata=client.V1ObjectMeta(owner_references=[
            client.V1OwnerReference(
                api_version='argoproj.io/v1alpha1',
                kind='Workflow',
                name='wf-1',
                uid='wf-uid-1')
        ]),
        spec=client.V1PodSpec(containers=[], service_account='sa-1')) 
开发者ID:tensorflow,项目名称:tfx,代码行数:12,代码来源:kubernetes_component_launcher_test.py

示例11: testToSwaggerDict

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1PodSpec [as 别名]
def testToSwaggerDict(self):
    pod = client.V1Pod(
        metadata=client.V1ObjectMeta(owner_references=[
            client.V1OwnerReference(
                api_version='argoproj.io/v1alpha1',
                kind='Workflow',
                name='wf-1',
                uid='wf-uid-1')
        ]),
        spec=client.V1PodSpec(containers=[], service_account='sa-1'))

    pod_dict = container_common.to_swagger_dict(pod)

    self.assertDictEqual(
        {
            'metadata': {
                'ownerReferences': [{
                    'apiVersion': 'argoproj.io/v1alpha1',
                    'kind': 'Workflow',
                    'name': 'wf-1',
                    'uid': 'wf-uid-1'
                }]
            },
            'spec': {
                'serviceAccount': 'sa-1'
            }
        }, pod_dict) 
开发者ID:tensorflow,项目名称:tfx,代码行数:29,代码来源:container_common_test.py

示例12: deploy

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1PodSpec [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) 
开发者ID:projectcalico,项目名称:node,代码行数:31,代码来源:test_base.py

示例13: simple_deployment

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1PodSpec [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
                                )
                            ]
                        )
                    ]
                )
            )
        )
    ) 
开发者ID:vapor-ware,项目名称:kubetest,代码行数:42,代码来源:conftest.py

示例14: simple_statefulset

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1PodSpec [as 别名]
def simple_statefulset():
    """Return the Kubernetes config matching the simple-statefulset.yaml manifest."""
    return client.V1StatefulSet(
        api_version='apps/v1',
        kind='StatefulSet',
        metadata=client.V1ObjectMeta(
            name='postgres-statefulset',
            labels={
                'app': 'postgres'
            }
        ),
        spec=client.V1StatefulSetSpec(
            replicas=3,
            selector=client.V1LabelSelector(
                match_labels={
                    'app': 'postgres'
                }
            ),
            service_name='simple-service',
            template=client.V1PodTemplateSpec(
                metadata=client.V1ObjectMeta(
                    labels={
                        'app': 'postgres'
                    }
                ),
                spec=client.V1PodSpec(
                    containers=[
                        client.V1Container(
                            name='postgres',
                            image='postgres:9.6',
                            ports=[
                                client.V1ContainerPort(
                                    container_port=5432
                                )
                            ]
                        )
                    ]
                )
            )
        )
    ) 
开发者ID:vapor-ware,项目名称:kubetest,代码行数:43,代码来源:conftest.py

示例15: simple_daemonset

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1PodSpec [as 别名]
def simple_daemonset():
    """Return the Kubernetes config matching the simple-daemonset.yaml manifest."""
    return client.V1DaemonSet(
        api_version='apps/v1',
        kind='DaemonSet',
        metadata=client.V1ObjectMeta(
            name='canal-daemonset',
            labels={
                'app': 'canal'
            }
        ),
        spec=client.V1DaemonSetSpec(
            selector=client.V1LabelSelector(
                match_labels={
                    'app': 'canal'
                }
            ),
            template=client.V1PodTemplateSpec(
                metadata=client.V1ObjectMeta(
                    labels={
                        'app': 'canal'
                    }
                ),
                spec=client.V1PodSpec(
                    containers=[
                        client.V1Container(
                            name='canal',
                            image='canal:3.7.2',
                            ports=[
                                client.V1ContainerPort(
                                    container_port=9099
                                )
                            ]
                        )
                    ]
                )
            )
        )
    ) 
开发者ID:vapor-ware,项目名称:kubetest,代码行数:41,代码来源:conftest.py


注:本文中的kubernetes.client.V1PodSpec方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。