Basic Kubernetes Commands
1. Running an Interactive Pod
Section titled “1. Running an Interactive Pod”To launch an ad-hoc debugging or exploration session with an interactive terminal:
kubectl run test-session \ --namespace sci-myproject \ --image=ubuntu:22.04 \ --restart=Never \ -it -- /bin/bash2. Deploying a Manifest (.yaml)
Section titled “2. Deploying a Manifest (.yaml)”Scientific workloads are defined using declarative YAML manifests.
Save the following as my-pod.yaml:
apiVersion: v1kind: Podmetadata: name: gpu-analysis-test namespace: sci-myprojectspec: restartPolicy: OnFailure containers: - name: worker image: registry.berkelium.lbl.gov/sci-als/synchrotron-model:v1 command: ["python", "app/evaluate.py"] resources: limits: cpu: "8" memory: "32Gi" nvidia.com/gpu: "1" requests: cpu: "4" memory: "16Gi" nvidia.com/gpu: "1"Apply and monitor the pod:
# Submit pod to the clusterkubectl apply -f my-pod.yaml
# Check statuskubectl get pods -n sci-myproject
# Follow logs in real-timekubectl logs -f gpu-analysis-test -n sci-myproject3. Useful Cheat Sheet
Section titled “3. Useful Cheat Sheet”# Get detailed status and scheduling eventskubectl describe pod <pod-name> -n sci-myproject
# Open a shell inside an active containerkubectl exec -it <pod-name> -n sci-myproject -- /bin/bash
# View resource usage (CPU & Memory)kubectl top pods -n sci-myproject
# Delete a completed or obsolete podkubectl delete pod <pod-name> -n sci-myproject