Deploy to Kubernetes
This guide covers deploying containerized Strands agents to Kubernetes using Kind (Kubernetes in Docker) for local and cloud development.
Prerequisites
Section titled “Prerequisites”- Docker deployment guide completed - You must have a working containerized agent before proceeding:
- Kind installed
- kubectl installed
Step 1: Setup Kind Cluster
Section titled “Step 1: Setup Kind Cluster”Create a Kind cluster:
kind create cluster --name my-clusterVerify cluster is running:
kubectl get nodesStep 2: Create Kubernetes Manifests
Section titled “Step 2: Create Kubernetes Manifests”The following assume you have completed the Docker deployment guide with the following file structure:
Project Structure (Python):
my-python-app/├── agent.py # FastAPI application (from Docker tutorial)├── Dockerfile # Container configuration (from Docker tutorial)├── pyproject.toml # Created by uv init└── uv.lock # Created automatically by uvProject Structure (TypeScript):
my-typescript-app/├── index.ts # Express application (from Docker tutorial)├── Dockerfile # Container configuration (from Docker tutorial)├── package.json # Created by npm init├── tsconfig.json # TypeScript configuration└── package-lock.json # Created automatically by npmAdd k8s-deployment.yaml to your project:
apiVersion: apps/v1kind: Deploymentmetadata: name: my-appspec: replicas: 1 selector: matchLabels: app: my-app template: metadata: labels: app: my-app spec: containers: - name: my-app image: my-image:latest imagePullPolicy: Never ports: - containerPort: 8080 env: - name: OPENAI_API_KEY value: "<your-api-key>"---apiVersion: v1kind: Servicemetadata: name: my-servicespec: selector: app: my-app ports: - port: 8080 targetPort: 8080 type: NodePortThis example k8s-deployment.yaml uses OpenAI, but any supported model provider can be configured. See the Strands documentation for all supported model providers. For instance, to include AWS credentials:
env: - name: AWS_ACCESS_KEY_ID value: "<your-access-key-id>" - name: AWS_SECRET_ACCESS_KEY value: "<your-secret-access-id>" - name: AWS_REGION value: "us-east-1"Step 3: Deploy to Kubernetes
Section titled “Step 3: Deploy to Kubernetes”Build and load your Docker image:
docker build -t my-image:latest .kind load docker-image my-image:latest --name my-clusterApply the Kubernetes manifests:
kubectl apply -f k8s-deployment.yamlVerify deployment:
kubectl get podskubectl get servicesStep 4: Test Your Deployment
Section titled “Step 4: Test Your Deployment”Port forward to access the service:
kubectl port-forward svc/my-service 8080:8080Test the endpoints:
# Health checkcurl http://localhost:8080/ping
# Test agent invocationcurl -X POST http://localhost:8080/invocations \ -H "Content-Type: application/json" \ -d '{"input": {"prompt": "What is artificial intelligence?"}}'Step 5: Making Changes
Section titled “Step 5: Making Changes”When you modify your code, redeploy with:
# Rebuild imagedocker build -t my-image:latest .
# Load into clusterkind load docker-image my-image:latest --name my-cluster
# Restart deploymentkubectl rollout restart deployment my-appCleanup
Section titled “Cleanup”Remove the Kind cluster when done:
kind delete cluster --name my-clusterOptional: Deploy to Cloud-Hosted Kubernetes
Section titled “Optional: Deploy to Cloud-Hosted Kubernetes”Once your application works locally with Kind, you can deploy it to any cloud-hosted Kubernetes cluster.
See our documentation for Deploying Strands Agents to Amazon EKS as an example.
Step 1: Push Container to Repository
Section titled “Step 1: Push Container to Repository”Push your image to a container registry:
# Tag and push to your registry (Docker Hub, ECR, GCR, etc.)docker tag my-image:latest <registry-url>/my-image:latestdocker push <registry-url>/my-image:latestStep 2: Update Deployment Configuration
Section titled “Step 2: Update Deployment Configuration”Update k8s-deployment.yaml for cloud deployment:
# Change image pull policy from:imagePullPolicy: Never# To:imagePullPolicy: Always
# Change image URL from:image: my-image:latest# To:image: <registry-url>/my-image:latest
# Change service type from:type: NodePort# To:type: LoadBalancerStep 3: Apply to Cloud Cluster
Section titled “Step 3: Apply to Cloud Cluster”# Connect to your cloud cluster (varies by provider)kubectl config use-context <cloud-context>
# Deploy your applicationkubectl apply -f k8s-deployment.yaml