我用Fabric8Kubernetes Java客户机API编写了一个示例,以设置容器上的GPU资源需求。我得到以下运行时错误:
spec.containers[0].resources.requests[gpu]: Invalid value: "gpu": must be a standard resource type or fully qualified,
spec.containers[0].resources.requests[gpu]: Invalid value: "gpu": must be a standard resource for containers.
示例的整个源代码如下:
/**
* Copyright (C) 2015 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.exam.docker.kubernetes.examples;
import io.fabric8.kubernetes.api.model.*;
import io.fabric8.kubernetes.client.*;
import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.ConfigBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
public class PodResExamples {
private static final Logger logger = LoggerFactory.getLogger(PodResExamples.class);
public static void main(String[] args) {
String master = "http://127.0.0.1:8080/";
if (args.length == 1) {
master = args[0];
}
String ns = "thisisatest";
String serviceName = "cuda-vector-add-"+ UUID.randomUUID();
Config config = new ConfigBuilder().withMasterUrl(master).build();
try (KubernetesClient client = new DefaultKubernetesClient(config)) {
try {
if(client.namespaces().withName(ns).get() == null) {
log("Create namespace:", client.namespaces().create(new NamespaceBuilder().withNewMetadata().withName(ns).endMetadata().build()));
}
String imageStr = "k8s.gcr.io/cuda-vector-add:v0.1";
String cmd = "";
final ResourceRequirements resources = new ResourceRequirementsBuilder()
.addToRequests("cpu", new Quantity("2"))
.addToRequests("memory", new Quantity("10Gi"))
.addToRequests("gpu", new Quantity("1"))
.build();
Container container = new ContainerBuilder().withName(serviceName)
.withImage(imageStr).withImagePullPolicy("IfNotPresent")
.withArgs(cmd)
.withResources(resources)
.build();
Pod createdPod = client.pods().inNamespace(ns).createNew()
.withNewMetadata()
.withName(serviceName)
.addToLabels("podres", "cuda-vector")
.endMetadata()
.withNewSpec()
.addToContainers(container)
.withRestartPolicy("Never")
.endSpec().done();
log("Created pod cuda-vector-add:", createdPod);
final CountDownLatch watchLatch = new CountDownLatch(1);
try (final Watch ignored = client.pods().inNamespace(ns).withLabel("podres").watch(new Watcher<Pod>() {
@Override
public void eventReceived(final Action action, Pod pod) {
if (pod.getStatus().getPhase().equals("Succeeded")) {
logger.info("Pod cuda-vector is completed!");
logger.info(client.pods().inNamespace(ns).withName(pod.getMetadata().getName()).getLog());
watchLatch.countDown();
} else if (pod.getStatus().getPhase().equals("Pending")) {
logger.info("Pod cuda-vector is Pending!");
}
}
@Override
public void onClose(final KubernetesClientException e) {
logger.info("Cleaning up pod.");
}
})) {
watchLatch.await(30, TimeUnit.SECONDS);
} catch (final KubernetesClientException | InterruptedException e) {
e.printStackTrace();
logger.error("Could not watch pod", e);
}
} catch (KubernetesClientException e) {
logger.error(e.getMessage(), e);
} finally {
log("Pod cuda-vector log: \n", client.pods().inNamespace(ns).withName(serviceName).getLog());
client.namespaces().withName(ns).delete();
}
}
}
private static void log(String action, Object obj) {
logger.info("{}: {}", action, obj);
}
private static void log(String action) {
logger.info(action);
}
}
参考Kubernetes文档,您可以尝试使用nvidia.com/GPU
而不是GPU
:
apiVersion: v1
kind: Pod
metadata:
name: cuda-vector-add
spec:
containers:
- name: cuda-vector-add
image: "k8s.gcr.io/cuda-vector-add:v0.1"
resources:
limits:
nvidia.com/gpu: 1 # requesting 1 GPU
如果您的应用程序使用AMD GPU,请尝试AMD.com/GPU
重要注意:除非您还设置了与请求相等的限制,否则不能设置GPU请求。
fabric8 kubernetes Java&Scala客户机API非常适合与kubernetes(或OpenShift)进行对话,但它的文档非常稀疏。向kubernetes Pod中运行的容器添加资源需求的代码示例是什么?
问题内容: 正如这个问题的标题所示,我想使用docker(docker.io)设置容器的最大磁盘/内存和cpu使用率。 有没有办法只使用docker来做到这一点? 问题答案: 内存/ CPU Docker现在支持更多资源分配选项: 通过-c标志分配CPU 内存限制,通过-m标志 特定的CPU内核,通过–cpuset标志 请查看更多详细信息。 如果使用lxc后端(),则可以指定更细粒度的资源分配方案
在java fx中,使用< code>%key符号的组件可以使用i18n标签。 比如说- 是否可以对组件值使用i18n? 以下代码不起作用-
问题内容: 因此,已经有一个必须在控制台上运行的Python程序设置了。我将使用Javascript为应用程序构建Web GUI界面。我将如何: 一种。开始处理此Python程序的输入/输出,而无需触摸原始代码。 b。通过Javascript调用将控制台输入发送到Python程序。我已经研究了原始的HTTP请求/ AJAX,但不确定如何将其作为输入发送到Python程序。 问题答案: 一种。处理程
我正在寻找一种从docker容器内部使用GPU的方法。