[Yandex Cloud documentation](../../index.md) > [Tutorials](../index.md) > [Container infrastructure](index.md) > Managed Service for Kubernetes > Running workloads with GPUs

# Running workloads with GPUs in Yandex Managed Service for Kubernetes

# Running workloads with GPUs


A [Managed Service for Kubernetes cluster](../../managed-kubernetes/concepts/index.md#kubernetes-cluster) allows running workloads on [graphics processing units](../../compute/concepts/gpus.md) (GPUs), which may be of use in tasks with special computing requirements.

To run workloads using GPUs on Managed Service for Kubernetes cluster [pods](../../managed-kubernetes/concepts/index.md#pod):

1. [Create a pod with a GPU](#create-pod-gpu).
1. [Test the pod](#check-pod).

If you no longer need the resources you created, [delete them](#delete-resources).


## Required paid resources {#paid-resources}

The support cost for this solution includes:

* Fee for a Managed Service for Kubernetes cluster: using the master and outbound traffic (see [Managed Service for Kubernetes pricing](../../managed-kubernetes/pricing.md)).
* Fee for cluster nodes (VMs): using computing resources, OS, and storage (see [Compute Cloud pricing](../../compute/pricing.md)).
* Fee for a public IP address if assigned to cluster nodes (see [Virtual Private Cloud pricing](../../vpc/pricing.md#prices-public-ip)).


## Getting started {#before-you-begin}

1. If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

   The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

1. [Create security groups](../../managed-kubernetes/operations/connect/security-groups.md) for the Managed Service for Kubernetes cluster and its node groups.

    {% note warning %}
    
    The configuration of security groups determines performance and availability of the cluster and the services and applications running in it.
    
    {% endnote %}

1. [Create a Managed Service for Kubernetes cluster](../../managed-kubernetes/operations/kubernetes-cluster/kubernetes-cluster-create.md) with any suitable configuration. When creating, specify the preconfigured security groups.
1. [Create a Managed Service for Kubernetes node group](../../managed-kubernetes/operations/node-group/node-group-create.md) with the following settings:
   * **Platform**: Select `With GPU` → `Intel Broadwell with NVIDIA® Tesla v100`.
   * **GPU**: Specify the required number of GPUs.
   * **Security groups**: Select the security groups you created earlier.

   {% note info %}
        
   The [cgroup v2](https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html) resource management mechanism is not supported for nodes on the Gen2 (`gpu-standard-v3i`) [platform](../../compute/concepts/vm-platforms.md#gpu-platforms).
   
   {% endnote %}

1. [Install kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl) and [configure it to work with the new cluster](../../managed-kubernetes/operations/connect/index.md#kubectl-connect).

## Create a pod with a GPU {#create-pod-gpu}

1. Save the GPU pod specification to a YAML file named `cuda-vector-add.yaml`:

   ```yaml
   apiVersion: v1
   kind: Pod
   metadata:
     name: cuda-vector-add
   spec:
     restartPolicy: OnFailure
     containers:
       - name: cuda-vector-add
         # https://github.com/kubernetes/kubernetes/blob/v1.7.11/test/images/nvidia-cuda/Dockerfile
         image: "registry.k8s.io/cuda-vector-add:v0.1"
         resources:
           limits:
             nvidia.com/gpu: 1 # Request for 1 GPU.
   ```

   Learn more about the pod creation specification in [this Kubernetes guide](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#pod-v1-core).
1. Create the pod with a GPU:

   ```bash
   kubectl create -f cuda-vector-add.yaml
   ```

## Test the pod {#check-pod}

1. View the information about the new pod:

   ```bash
   kubectl describe pod cuda-vector-add
   ```

   Result:

   ```text
   Name:         cuda-vector-add
   Namespace:    default
   Priority:     0
   ...
     Normal  Pulling    16m   kubelet, cl1i7hcbti99********-ebyq  Successfully pulled image "registry.k8s.io/cuda-vector-add:v0.1"
     Normal  Created    16m   kubelet, cl1i7hcbti99********-ebyq  Created container cuda-vector-add
     Normal  Started    16m   kubelet, cl1i7hcbti99********-ebyq  Created container
   ```

1. View the pod logs:

   ```bash
   kubectl logs -f cuda-vector-add
   ```

   Result:

   ```text
   [Vector addition of 50000 elements]
   Copy input data from the host memory to the CUDA device
   CUDA kernel launch with 196 blocks of 256 threads
   Copy output data from the CUDA device to the host memory
   Test PASSED
   Done
   ```

## Delete the resources you created {#clear-out}

Delete the resources you no longer need to avoid paying for them:
1. [Delete the Managed Service for Kubernetes cluster](../../managed-kubernetes/operations/kubernetes-cluster/kubernetes-cluster-delete.md).
1. [Delete](../../vpc/operations/address-delete.md) the public static [IP address](../../vpc/concepts/address.md) for your Managed Service for Kubernetes cluster if you reserved one.