Kubernetes Deployment¶
This guide covers deploying PrimeStamp on Kubernetes for production-grade, horizontally scalable operation.
Prerequisites¶
- A Kubernetes cluster (1.24+)
kubectlconfigured for your cluster- The PrimeStamp Docker image built and pushed to a registry (see Docker guide)
Namespace¶
Secret¶
Store sensitive configuration in a Kubernetes Secret.
# primestamp-secret.yaml
apiVersion: v1
kind: Secret
metadata:
name: primestamp-secret
namespace: primestamp
type: Opaque
stringData:
PRIMESTAMP_PRIVATE_KEY: "base64_encoded_ed25519_key"
PRIMESTAMP_API_KEY: "your-api-key"
ETHEREUM_RPC_URL: "https://mainnet.infura.io/v3/YOUR_KEY"
Deployment¶
# primestamp-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: primestamp-api
namespace: primestamp
labels:
app: primestamp
spec:
replicas: 3
selector:
matchLabels:
app: primestamp
template:
metadata:
labels:
app: primestamp
spec:
containers:
- name: primestamp
image: your-registry/primestamp:latest
ports:
- containerPort: 8800
envFrom:
- secretRef:
name: primestamp-secret
env:
- name: PRIMESTAMP_PRESET
value: "standard"
- name: PRIMESTAMP_LOG_LEVEL
value: "info"
resources:
requests:
cpu: "250m"
memory: "256Mi"
limits:
cpu: "1000m"
memory: "512Mi"
livenessProbe:
httpGet:
path: /health
port: 8800
initialDelaySeconds: 10
periodSeconds: 30
readinessProbe:
httpGet:
path: /health
port: 8800
initialDelaySeconds: 5
periodSeconds: 10
volumeMounts:
- name: data
mountPath: /app/data
volumes:
- name: data
persistentVolumeClaim:
claimName: primestamp-data
Service¶
# primestamp-service.yaml
apiVersion: v1
kind: Service
metadata:
name: primestamp-api
namespace: primestamp
spec:
selector:
app: primestamp
ports:
- port: 80
targetPort: 8800
protocol: TCP
type: ClusterIP
Ingress¶
# primestamp-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: primestamp-ingress
namespace: primestamp
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
tls:
- hosts:
- api.primestamp.example.com
secretName: primestamp-tls
rules:
- host: api.primestamp.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: primestamp-api
port:
number: 80
Persistent Volume¶
# primestamp-pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: primestamp-data
namespace: primestamp
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: standard
Apply All Resources¶
kubectl apply -f primestamp-secret.yaml
kubectl apply -f primestamp-pvc.yaml
kubectl apply -f primestamp-deployment.yaml
kubectl apply -f primestamp-service.yaml
kubectl apply -f primestamp-ingress.yaml
Horizontal Pod Autoscaler¶
# primestamp-hpa.yaml
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: primestamp-hpa
namespace: primestamp
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: primestamp-api
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
Resource Recommendations¶
| Workload | Replicas | CPU Request | Memory Request |
|---|---|---|---|
| Development | 1 | 250m | 256Mi |
| Staging | 2 | 500m | 512Mi |
| Production | 3+ | 1000m | 1Gi |
Shared Storage
When running multiple replicas, use a shared storage backend (S3, IPFS, or a ReadWriteMany PVC) instead of local file storage. Set PRIMESTAMP_STORAGE=s3 or PRIMESTAMP_STORAGE=ipfs and configure the appropriate credentials.
Secrets Management
For production, consider using an external secrets manager such as HashiCorp Vault, AWS Secrets Manager, or the Kubernetes External Secrets Operator instead of plain Kubernetes Secrets.
Monitoring¶
Expose Prometheus metrics by setting PRIMESTAMP_METRICS=true. Scrape the /metrics endpoint on port 8800.