Kubernetes Quickstart
Estimated time: 6 minutes, 8 minutes with buffer.
Installing Tooling
We'll start by installing kubectl and k3d. kubectl is a command-line tool for managing kubernetes interfaces, and k3d is a lightweight wrapper to run k3s in Docker. Download and install the lateset release of kubectl using the folllowing commands:
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectlNext, install the latest release of k3d using this command:
wget -q -O - https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bashCreating and Configuring a Cluster
Now, you must create a cluster:
k3d cluster create hello-world-clusterThen go ahead and check your context:
kubectl config current-contextThis should list the cluster you just created, but if not, run the following command to switch to the needed context:
kubectl config use-context k3d-hello-world-clusterIn order to operate with acceleration, Kubernetes must also be set up with the AMD GPU Operator and Labeler plugins. You can install these using the following commands:
kubectl create -f https://raw.githubusercontent.com/ROCm/k8s-device-plugin/master/k8s-ds-amdgpu-dp.yaml
kubectl create -f https://raw.githubusercontent.com/ROCm/k8s-device-plugin/master/k8s-ds-amdgpu-labeller.yamlThen, go ahead and make your deployment manifest. Create a directory for your manifest and direct into it, then open up a deployment.yaml file.
mkdir k8s-hello-world
cd k8s-hello-world
nano deployment.yamlFrom there, paste in the following yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-world
spec:
replicas: 1
selector:
matchLabels:
app: hello-world
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-world
image: tensorwavehq/hello_world:latest
resources:
limits:
amd.com/gpu: 1
volumeMounts:
- name: dev-kfd
mountPath: /dev/kfd
- name: dev-dri
mountPath: /dev/dri
securityContext:
runAsGroup: 110
volumes:
- name: dev-kfd
hostPath:
path: /dev/kfd
- name: dev-dri
hostPath:
path: /dev/driYou'll notice there are a few extra configurations we added. These are necessary to running the pod with GPU acceleration.
resources: limits: amd.com/gpu: 1This specifies that the container requires 1 AMD GPU. You must explicitly request GPU resources so that Kubernetes can schedule the pod on a node with an available AMD GPU.
volumes: - name: dev-kfd hostPath: path: /dev/kfd - name: dev-dri hostPath: path: /dev/driThese definitions allow the cluster to use the necessary volumes from the host for utilizing the AMD GPUs.
volumeMounts: - name: dev-kfd mountPath: /dev/kfd - name: dev-dri mountPath: /dev/driThese mounts correspond to the above volumes, allowing the container to access the GPU hardware.
securityContext: runAsGroup: 110This security context runs the containers in the pod as the group ID 110, the render group, which is necessary for PyTorch to detect the devices properly (PyTorch is used in the hello world container).
Continue by applying the manifest using the following:
kubectl apply -f deployment.yamlThis should take a few minutes to create the container. You can monitor the status here:
kubectl get pods -l app=hello-worldOnce this output displays that STATUS is Completed, you're ready to check output. Running:
kubectl logs -l app=hello-worldShould give an output of:
CUDA available: True
Number of GPUs: 1
GPU 0: AMD Instinct MI300XYou'll notice that you only have one GPU. That's because, as covered earlier, we specified a resource limit of one. You may raise or lower this number as necessary.
Teardown
Navigate back to your base directory and remove your k8s-hello-world folder:
cd ~
rm -rf k8s-hello-world/Last updated

