GKE 에이전트 샌드박스와 함께 Filestore 에이전트 볼륨 사용

Google Kubernetes Engine (GKE) 에이전트 샌드박스는 gVisor를 사용하여 신뢰할 수 없는 모델 생성 코드에 커널 수준 격리를 제공합니다. GKE 에이전트 샌드박스를 Filestore 에이전트 볼륨과 결합하면 영구적인 고밀도 파일 스토리지를 기반으로 하는 안전한 격리된 환경을 제공할 수 있습니다.

이 가이드에서는 gVisor 지원 노드 풀을 구성하고, Filestore 볼륨 요청 템플릿으로 SandboxTemplate를 정의하고, SandboxWarmPool로 샌드박스를 미리 준비하고, SandboxClaim로 샌드박스를 요청하는 방법을 보여줍니다.

시작하기 전에

Filestore 에이전트 볼륨용 GKE 환경 설정에서 클러스터 및 CSI 드라이버 설정을 완료합니다.

gVisor 지원 노드 풀 만들기

gVisor 샌드박스 격리로 구성된 전용 노드 풀을 만듭니다.

gcloud container node-pools create gvisor-pool \
    --cluster=CLUSTER_NAME \
    --location=REGION \
    --project=PROJECT_ID \
    --image-type=cos_containerd \
    --sandbox=type=gvisor \
    --num-nodes=2 \
    --machine-type=n2-standard-16 \
    --enable-autoscaling \
    --min-nodes=1 \
    --max-nodes=10 \
    --scopes=cloud-platform

다음을 바꿉니다.

  • CLUSTER_NAME: GKE 클러스터의 이름입니다.
  • REGION: 클러스터가 상주하는 리전입니다.
  • PROJECT_ID: Google Cloud 프로젝트 ID입니다.

SandboxTemplate 만들기

warmpool-filestore-template.yaml이라는 SandboxTemplate 매니페스트를 정의합니다. 이 템플릿은 gVisor 런타임 설정, 비루트 보안 컨텍스트, volume-pool-sc StorageClass을 타겟팅하는 volumeClaimTemplates 블록을 구성합니다.

apiVersion: extensions.agents.x-k8s.io/v1alpha1
kind: SandboxTemplate
metadata:
  name: warmpool-filestore-template
  namespace: default
spec:
  podTemplate:
    spec:
      runtimeClassName: gvisor
      automountServiceAccountToken: false
      securityContext:
        runAsNonRoot: true
        runAsUser: 1000
        fsGroup: 1000
      nodeSelector:
        sandbox.gke.io/runtime: gvisor
      tolerations:
        - key: "sandbox.gke.io/runtime"
          value: "gvisor"
          effect: "NoSchedule"
      containers:
        - name: agent-container
          image: busybox
          command: ["/bin/sh", "-c"]
          args:
            - |
              echo "Sandbox started with Filestore volume mounted!"
              ls -la /workspace
              date > /workspace/session-init.txt
              cat /workspace/session-init.txt
              sleep 3600
          securityContext:
            capabilities:
              drop: ["ALL"]
            allowPrivilegeEscalation: false
          resources:
            requests:
              cpu: "250m"
              memory: "256Mi"
            limits:
              cpu: "500m"
              memory: "512Mi"
          volumeMounts:
            - name: agent-workspace
              mountPath: /workspace
  volumeClaimTemplates:
    - metadata:
        name: agent-workspace
      spec:
        accessModes: ["ReadWriteMany"]
        storageClassName: "volume-pool-sc"
        resources:
          requests:
            storage: "1Gi"

매니페스트를 적용합니다.

kubectl apply -f warmpool-filestore-template.yaml

SandboxWarmPool 만들기

샌드박스 시작 지연 시간을 최소화하려면 미리 워밍된 포드 인스턴스를 유지하는 sandbox-warmpool.yaml SandboxWarmPool매니페스트를 정의하세요.

apiVersion: extensions.agents.x-k8s.io/v1alpha1
kind: SandboxWarmPool
metadata:
  name: filestore-warmpool
  namespace: default
spec:
  replicas: 3
  sandboxTemplateRef:
    name: warmpool-filestore-template

매니페스트를 적용합니다.

kubectl apply -f sandbox-warmpool.yaml

웜 풀 포드가 준비되었는지 확인합니다.

kubectl get sandboxwarmpool filestore-warmpool -n default

샌드박스 포드 요청

에이전트 세션이 시작되면 sandbox-claim.yaml라는 SandboxClaim 매니페스트를 제출하여 사전 워밍된 샌드박스를 요청합니다.

apiVersion: extensions.agents.x-k8s.io/v1alpha1
kind: SandboxClaim
metadata:
  name: agent-session-1
  namespace: default
spec:
  sandboxTemplateRef:
    name: warmpool-filestore-template

매니페스트를 적용합니다.

kubectl apply -f sandbox-claim.yaml

마운트된 볼륨 확인

  1. 클레임이 포드에 바인딩되어 있는지 확인합니다.

    kubectl get sandboxclaim agent-session-1
    
  2. 클레임과 연결된 포드를 찾습니다.

    kubectl get pods -l extensions.agents.x-k8s.io/claimed-by=agent-session-1
    
  3. 볼륨이 클레임된 컨테이너 내에 마운트되었는지 확인합니다.

    kubectl logs POD_NAME -c agent-container
    

    POD_NAME을 이전 단계에서 반환된 포드의 이름으로 바꿉니다.

    로그를 통해 마운트된 Filestore 볼륨에 /workspace/session-init.txt가 생성되었음을 확인할 수 있습니다.

다음 단계