EKS集群单个pod内多个容器如何共享GPU卡

弹性容器服务(Elastic Kubernetes Service,EKS)是腾讯云容器服务推出的无须用户购买节点即可部署工作负载的服务模式。弹性容器服务 EKS 完全兼容原生 Kubernetes,支持使用原生方式购买及管理资源,按照容器真实使用的资源量计费。弹性容器服务 EKS 还扩展支持腾讯云的存储及网络等产品,同时确保用户容器的安全隔离,开箱即用。

现在很多企业会把自己的业务部署到eks集群上,其中有些深度学习业务会需要用到GPU资源,eks也是支持gpu部署的,但是因为eks存在一些局限性,不像tke有qgpu这类组件支持gpu共享。
但是很多时候,我们的一个pod会有多个容器,这些容器都需要用到gpu资源,如果给每个容器申请一张gpu卡,由于gpu资源比较昂贵,这样会极大的增加成本。

eks上一个pod就相当于一台微型的CVM资源,那么这里是否可以一个pod申请一张GPU卡,然后pod内的多个容器共享这一张GPU卡呢?下面我们说说如何配置多个容器共享pod的GPU卡。

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    k8s-app: gpu-test1
    qcloud-app: gpu-test1
  name: gpu-test1
  namespace: weixnie
spec:
  replicas: 1
  selector:
    matchLabels:
      k8s-app: gpu-test1
      qcloud-app: gpu-test1
  template:
    metadata:
      annotations:
        eks.tke.cloud.tencent.com/gpu-type: T4
      labels:
        k8s-app: gpu-test1
        qcloud-app: gpu-test1
    spec:
      containers:
      - args:
        - 70d
        command:
        - sleep
        image: centos:7
        imagePullPolicy: IfNotPresent
        name: container1
        resources:
          limits:
            nvidia.com/gpu: "1"
          requests:
            nvidia.com/gpu: "1"
        securityContext:
          privileged: true
      - args:
        - 70d
        command:
        - sleep
        env:
        - name: NVIDIA_VISIBLE_DEVICES
          value: all
        image: centos:7
        imagePullPolicy: IfNotPresent
        name: container2
        resources: {}
        securityContext:
          privileged: true
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      imagePullSecrets:
      - name: qcloudregistrykey
      restartPolicy: Always

具体的yaml配置如上,下面我们来说明下需要配置的几个点

  • 注解指定gpu卡类型
template:
    metadata:
      annotations:
        eks.tke.cloud.tencent.com/gpu-type: T4 # 这里指定的是T4类型GPU卡
  • 其中一个容器声明申请的gpu卡数量,eks上申请gpu卡数量是根据容器设置的request和limit配置来申请的
name: container1
resources:
  limits:
    nvidia.com/gpu: "1"
  requests:
    nvidia.com/gpu: "1"
  • 多容器共享gpu配置,配置环境变量NVIDIA_VISIBLE_DEVICES,容器设置为特权模式
        env:
        - name: NVIDIA_VISIBLE_DEVICES
          value: all
        image: centos:7
        imagePullPolicy: IfNotPresent
        name: container2
        resources: {}
        securityContext:
          privileged: true

配置好之后,启动pod,你可以发现2个容器都能正常启动,并且只申请了一张gpu卡,这里2个容器就都能使用gpu资源了。

本站文章资源均来源自网络,除非特别声明,否则均不代表站方观点,并仅供查阅,不作为任何参考依据!
如有侵权请及时跟我们联系,本站将及时删除!
如遇版权问题,请查看 本站版权声明
THE END
分享
二维码
海报
EKS集群单个pod内多个容器如何共享GPU卡
弹性容器服务(Elastic Kubernetes Service,EKS)是腾讯云容器服务推出的无须用户购买节点即可部署工作负载的服务模式。弹性容器服务 EK...
<<上一篇
下一篇>>