Run Claude Code with Kubernetes
job.yaml runs Claude Code once as a Job with
claude -p "review the workspace", prints the answer to the pod log, and exits.
- Images
- GHCR
ghcr.io/hambn/claude-code - Docker Hub
docker.io/hambn/claude-code
- GHCR
- Use case
- One-shot review in a cluster from plain manifests
Prerequisites
- A Kubernetes cluster and
kubectlconfigured for it. - An Anthropic API key.
Run the Job
Shell
kubectl create secret generic claude-code --from-literal=ANTHROPIC_API_KEY="$ANTHROPIC_API_KEY"
kubectl apply -f job.yaml
kubectl logs -f job/claude-codeEdit args in job.yaml to change the prompt or flags. The Job uses
ghcr.io/hambn/claude-code:ubuntu-browser; replace the tag with @sha256:<digest> to
pin one build.
Variables
| Name | Where | Purpose |
|---|---|---|
ANTHROPIC_API_KEY |
Secret claude-code |
Read through secretKeyRef, so the key is not in the manifest. |
Workspace
As shipped, /workspace is an empty emptyDir, so the default prompt has nothing to
review. Replace the volume with a PersistentVolumeClaim that holds your code, or add an
init container that clones your repository into it.
Files
job.yamlis a non-root Job with all capabilities dropped,backoffLimit: 0, and CPU and memory limits.
Cleanup
Shell
kubectl delete -f job.yaml
kubectl delete secret claude-codeA finished Job stays until you delete it. Delete it before applying the manifest again to start a new run.
File contents
job.yaml46 lines
# One-shot Claude Code run. Create the secret first:
# kubectl create secret generic claude-code --from-literal=ANTHROPIC_API_KEY=sk-...
apiVersion: batch/v1
kind: Job
metadata:
name: claude-code
spec:
backoffLimit: 0
template:
spec:
restartPolicy: Never
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
fsGroup: 1000
seccompProfile:
type: RuntimeDefault
containers:
- name: claude
image: ghcr.io/hambn/claude-code:ubuntu-browser
imagePullPolicy: Always
args: ["-p", "review the workspace"]
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
resources:
requests:
cpu: 100m
memory: 256Mi
limits:
cpu: "1"
memory: 1Gi
env:
- name: ANTHROPIC_API_KEY
valueFrom:
secretKeyRef:
name: claude-code
key: ANTHROPIC_API_KEY
volumeMounts:
- name: workspace
mountPath: /workspace
volumes:
- name: workspace
emptyDir: {}