Skip to content

Instantly share code, notes, and snippets.

@neoaggelos
Last active May 29, 2023 14:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save neoaggelos/a4244cc92f76599b0d8febfeae3a28a8 to your computer and use it in GitHub Desktop.
Save neoaggelos/a4244cc92f76599b0d8febfeae3a28a8 to your computer and use it in GitHub Desktop.
Bash script to enable GPU support on MicroK8s 1.21
#!/bin/bash
# The script below documents the steps needed to install the NVIDIA GPU operator on MicroK8s 1.21 (for Ubuntu OS)
# 1. install microk8s and enable required addons
sudo snap install microk8s --classic --channel 1.21
microk8s enable dns
microk8s enable helm3
# 2. install nvidia drivers
sudo apt-get install nvidia-headless-510-server nvidia-utils-510-server
# 3. ensure nvidia drivers are loaded
if ! nvidia-smi -L; then
echo "No compatible GPU found"
fi
# 4. install nvidia-container-runtime
curl -s -L https://nvidia.github.io/nvidia-container-runtime/gpgkey | \
sudo apt-key add -
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-container-runtime/$distribution/nvidia-container-runtime.list | \
sudo tee /etc/apt/sources.list.d/nvidia-container-runtime.list
sudo apt-get update
sudo apt-get install -y nvidia-container-runtime
# 5. configure and restart containerd
echo '
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.nvidia]
runtime_type = "io.containerd.runc.v2"
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.nvidia.options]
BinaryName = "/usr/bin/nvidia-container-runtime"
' | sudo tee -a /var/snap/microk8s/current/args/containerd-template.toml
sudo snap restart microk8s.daemon-containerd
# 6. install GPU operator
sudo microk8s helm3 repo add nvidia https://nvidia.github.io/gpu-operator
sudo microk8s helm3 install gpu-operator nvidia/gpu-operator \
--create-namespace -n gpu-operator-resources \
--set driver.enabled=false,toolkit.enabled=false
# 7. wait for validations to complete
while ! sudo microk8s kubectl logs -n gpu-operator-resources -lapp=nvidia-operator-validator | grep "all validations are successful"
do
echo "Waiting for GPU addon"
sleep 5
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment