Com as GPUs NVIDIA de nível empresarial incluídas na SKU otimizada para IA da Sandbox do GDC, é possível desenvolver e testar aplicativos exigentes de treinamento e inferência de IA, como a IA generativa.
O Gemma é um modelo de linguagem grande leve baseado na tecnologia do Gemini. Este guia mostra como implantar o Gemma com Ollama e Open-WebUI no GDC Sandbox e tem os seguintes objetivos.
- Implante o Ollama com o modelo Gemma em um sandbox do GDC otimizado para IA com GPUs.
- Envie comandos para o serviço Ollama no endpoint particular pela interface Open-WebUI.
Antes de começar
As GPUs no GDC Sandbox estão incluídas no cluster org-infra.
Para executar comandos no cluster de infraestrutura da organização, verifique se você tem o kubeconfig do cluster
org-1-infra
, conforme descrito em Trabalhar com clusters:- Configure e autentique com a linha de comando
gdcloud
e - gere o arquivo kubeconfig para o cluster de infraestrutura da organização e
atribua o caminho dele à variável de ambiente
KUBECONFIG
.
- Configure e autentique com a linha de comando
Verifique se o usuário tem a função
sandbox-gpu-admin
atribuída ao projetosandbox-gpu-project
. Por padrão, a função é atribuída ao usuárioplatform-admin
. Você pode atribuir a função a outros usuários fazendo login comoplatform-admin
e executando o seguinte comando:kubectl --kubeconfig ${KUBECONFIG} create rolebinding ${NAME} --role=sandbox-gpu-admin \ --user=${USER} --namespace=sandbox-gpu-project
Configure o repositório do Artifact Registry conforme descrito em Usar o Artifact Registry e faça login para enviar e extrair imagens do registro de artefatos.
Implantar o modelo Gemma com Ollama e Open-WebUI
A implantação é organizada por um conjunto de arquivos de configuração do Kubernetes (manifestos YAML), cada um definindo um componente ou serviço específico.
Crie um Dockerfile com o Gemma pré-baixado.
FROM ubuntu # Install Ollama # This uses Ollamas official installation script, which adds Ollama to /usr/local/bin RUN apt-get update && apt-get install -y --no-install-recommends curl ca-certificates RUN curl -fsSL https://ollama.com/install.sh -o install.sh RUN chmod +x install.sh RUN ./install.sh && \ rm -rf /var/lib/apt/lists/* # Set environment variables for Ollama (optional, but good practice) ENV OLLAMA_HOST="0.0.0.0" # ENV OLLAMA_MODELS="/usr/local/ollama/models" # Default is /root/.ollama # If you want to customize the model storage path within the container, set OLLAMA_MODELS # and then ensure you create and populate that directory. Default is usually fine for pre-downloaded. # --- Predownload Gemma Model --- # This step starts Ollama server in the background, pulls the model, # and then kills the server to allow the Docker build to continue. # This approach works around Docker''s RUN command limitations for services. RUN ollama serve & \ sleep 5 && \ # Give the Ollama server a moment to start up # Use --retry and --retry-connrefused to handle startup delays curl --retry 10 --retry-connrefused -s http://localhost:11434 || true && \ echo "Attempting to pull gemma:7b..." && \ ollama pull gemma:7b && \ echo "Model pull complete. Cleaning up background Ollama process." && \ pkill ollama || true # Gracefully kill the ollama serve process # Expose Ollama's default port EXPOSE 11434 # Command to run Ollama server when the container starts CMD ["ollama", "serve"]
Crie a imagem do Docker e faça upload dela no repositório do Artifact Registry.
docker build -t ollama-gemma . docker tag ollama-gemma REGISTRY_REPOSITORY_URL/ollama-gemma:latest docker push REGISTRY_REPOSITORY_URL/ollama-gemma:latest
Substitua:
REGISTRY_REPOSITORY_URL
com o URL do repositório.
Crie um secret para salvar as credenciais do Docker.
export SECRET=DOCKER_REGISTRY_SECRET export DOCKER_TEST_CONFIG=~/.docker/config.json kubectl --kubeconfig ${KUBECONFIG}$ create secret docker-registry ${SECRET} --from-file=.dockerconfigjson=${DOCKER_TEST_CONFIG} -n sandbox-gpu-project
Substitua:
- Nome do secret
DOCKER_REGISTRY_SECRET
.
- Nome do secret
Crie um arquivo
ollama-deployment.yaml
para definir a implantação do mecanismo de IA do Ollama:A implantação do servidor Ollama exige uma GPU.
apiVersion: apps/v1 kind: Deployment metadata: annotations: deployment.kubernetes.io/revision: "9" name: ollama namespace: sandbox-gpu-project spec: progressDeadlineSeconds: 600 replicas: 1 revisionHistoryLimit: 10 selector: matchLabels: app: ollama strategy: rollingUpdate: maxSurge: 25% maxUnavailable: 25% type: RollingUpdate template: metadata: creationTimestamp: null labels: app: ollama egress.networking.gke.io/enabled: "true" spec: containers: - name: ollama image: REGISTRY_REPOSITORY_URL/ollama-gemma:latest imagePullPolicy: Always ports: - containerPort: 11434 protocol: TCP resources: limits: nvidia.com/gpu-pod-NVIDIA_H100_80GB_HBM3: "1" requests: nvidia.com/gpu-pod-NVIDIA_H100_80GB_HBM3: "1" env: - name: OLLAMA_HOST value: 0.0.0.0 - name: OLLAMA_ORIGINS value: http://localhost:8080,http://ollama-webui.ollama-llm.svc.cluster.local:8080,http://ollama-webui:8080 securityContext: seLinuxOptions: type: unconfined_t terminationMessagePath: /dev/termination-log terminationMessagePolicy: File imagePullSecrets: - name: DOCKER_REGISTRY_SECRET dnsConfig: nameservers: - 8.8.8.8 dnsPolicy: ClusterFirst restartPolicy: Always schedulerName: default-scheduler terminationGracePeriodSeconds: 30
Substitua:
REGISTRY_REPOSITORY_URL
: o URL do repositório.DOCKER_REGISTRY_SECRET
: nome do secret.
Crie o arquivo
ollama-service.yaml
para expor o servidor Ollama internamente.apiVersion: v1 kind: Service metadata: name: ollama namespace: sandbox-gpu-project annotations: metallb.universe.tf/ip-allocated-from-pool: lb-address-pool-0-ptleg spec: type: LoadBalancer selector: app: ollama ports: - port: 11434 nodePort: 30450 ipFamilyPolicy: SingleStack ipFamilies: - IPv4 clusterIPs: - 10.1.122.216 clusterIP: 10.1.122.216
Aplicar os manifestos
kubectl --kubeconfig ${KUBECONFIG} apply -f ollama-deployment.yaml kubectl --kubeconfig ${KUBECONFIG} apply -f ollama-service.yaml
Verifique se os pods do ollama estão em execução.
kubectl --kubeconfig ${KUBECONFIG} get deployments -n sandbox-gpu-project kubectl --kubeconfig ${KUBECONFIG} get service -n sandbox-gpu-project
Anote o IP externo do serviço Ollama
OLLAMA_BASE_END_POINT
na saída.kubectl --kubeconfig ${KUBECONFIG} get service ollama \ -n sandbox-gpu-project -o jsonpath='{.status.loadBalancer.ingress[*].ip}'
Crie o arquivo
openweb-ui-deployment.yaml
para implantar a interface Open-WebUI.apiVersion: apps/v1 kind: Deployment metadata: name: ollama-webui namespace: sandbox-gpu-project labels: app: ollama-webui annotations: deployment.kubernetes.io/revision: "5" spec: replicas: 1 selector: matchLabels: app: ollama-webui strategy: type: RollingUpdate rollingUpdate: maxSurge: 25% maxUnavailable: 25% progressDeadlineSeconds: 600 revisionHistoryLimit: 10 template: metadata: labels: app: ollama-webui creationTimestamp: null spec: containers: - name: ollama-webui image: ghcr.io/open-webui/open-webui:main imagePullPolicy: IfNotPresent ports: - name: http containerPort: 8080 protocol: TCP env: - name: OLLAMA_BASE_URL value: OLLAMA_BASE_END_POINT - name: PORT value: "8080" terminationMessagePath: /dev/termination-log terminationMessagePolicy: File restartPolicy: Always dnsPolicy: ClusterFirst schedulerName: default-scheduler terminationGracePeriodSeconds: 30
Substitua:
OLLAMA_BASE_END_POINT
: o endereço IP externo do serviço Ollama.
Crie um arquivo
ollama-webui-service.yaml
para expor externamente a interface webui aberta.apiVersion: v1 kind: Service metadata: name: ollama-webui namespace: sandbox-gpu-project annotations: metallb.universe.tf/ip-allocated-from-pool: lb-address-pool-0-ptleg spec: type: LoadBalancer ipFamilyPolicy: SingleStack ipFamilies: - IPv4 clusterIPs: - 10.1.104.52 clusterIP: 10.1.104.52 ports: - port: 80 targetPort: 8080 nodePort: 32351 selector: app: ollama-webui
Aplique os manifestos
openweb-ui-deployment.yaml
eollama-webui-service.yaml
ao cluster.kubectl --kubeconfig ${KUBECONFIG} apply -f openweb-ui-deployment.yaml kubectl --kubeconfig ${KUBECONFIG} apply -f ollama-webui-service.yaml
Crie uma política de rede do projeto para permitir o tráfego de entrada de endereços IP externo.
kubectl --kubeconfig ${KUBECONFIG} apply -f - <<EOF apiVersion: networking.global.gdc.goog/v1 kind: ProjectNetworkPolicy metadata: namespace: sandbox-gpu-project name: allow-inbound-traffic-from-external spec: policyType: Ingress subject: subjectType: UserWorkload ingress: - from: - ipBlock: cidr: 0.0.0.0/0 EOF
Identifique o IP externo do serviço Ollama executando o seguinte comando: Anote-o para usar nas etapas posteriores, em que você vai substituir esse valor por
OPEN_WEB_UI_ENDPOINT
.kubectl --kubeconfig ${KUBECONFIG} get service -n sandbox-gpu-project
Abra o Google Chrome e insira o URL usando o endereço IP externo encontrado na etapa anterior. Agora é possível interagir com o modelo Gemma pela interface da Web aberta.
http://OPEN_WEB_UI_ENDPOINT/