Write workload manifests
A step-by-step guide for creating Kubernetes manifests for user workloads in Multicloud K3S clusters.
Each Multicloud cluster is an isolated workload environment belonging to a client. Workloads are completely segregated by namespace with no cross-cluster or cross-tenant access.
This is the low-level path. Hand-authoring
Deployment/Service/IngressYAML is the escape hatch, not the default. The default workload path is now themulticloud.deploycompiler + Knative Serving — you write a shortmulticloud.deploydocument and the compiler emits the Knative Service. Reach for the raw manifests below only when Knative can't express what you need. Ask Multicloud support for themulticloud.deployv0 schema.
For placement (architecture, region, zone, spot, spread, anti-affinity) and troubleshooting a Pending pod, see Kubernetes on Multicloud.
Core Concepts
Namespace Isolation
Each Multicloud cluster has one namespace per tenant/project. The namespace isolates compute, networking, storage, and secrets from all other workloads.
Multicloud Cluster (shared infrastructure)
├─ Namespace: multicloud-client-a
│ ├─ Deployment: client-a-frontend
│ ├─ Deployment: client-a-backend
│ └─ Service: client-a-frontend
│
├─ Namespace: multicloud-client-b
│ ├─ Deployment: client-b-app
│ └─ Service: client-b-app
│
└─ Namespace: multicloud-hosting (platform services)
├─ Deployment: keycloak
└─ DaemonSet: cilium-agent
Namespace naming convention: multicloud-<client-name> or multicloud-<project-name>
Example: multicloud-example, multicloud-acme-corp, multicloud-customer-xyz
Workload Naming
All workload names (Deployments, Services, PodDisruptionBudgets, etc.) must be descriptive and include the project/client prefix to avoid ambiguity in logs and dashboards.
Pattern: <project>-<component> or <project>-<component>-<role>
| Bad | Good | Reason |
|---|---|---|
backend |
example-backend |
Disambiguates in shared dashboards |
frontend |
example-frontend |
Clear which app and which role |
api |
acme-api-server |
Scope and component visible at a glance |
worker |
myapp-worker-queue |
Component type explicit |
All references in the manifest (app labels, selectors, environment variables, ingress backends) use the full descriptive name.
1. Pre-flight Requirements Checklist
Before writing a manifest, answer these questions:
- Workload type: Stateless web app? Long-running daemon? Batch job? Async worker?
- Namespace: Does it exist? What's the client/project name? Format:
multicloud-<name> - Number of instances: Single replica? Multiple replicas? Per-node?
- Resource needs: CPU request/limit? Memory? GPU?
- Networking:
- Does it need public ingress? (HTTPS, domain name)
- Does it need internal service discovery? (in-cluster only)
- Does it need IPv4 reachability? (hostNetwork required)
- Does it need specific ports?
- Authentication:
- Public (no auth)?
- mTLS (certificate-based)?
- OAuth2 (Keycloak login)?
- Secrets: Database credentials? API keys? SSH keys?
- Data:
- Stateful (PersistentVolume needed)?
- Artifacts from S3/GitHub?
- Logs to external system?
- High availability:
- Multiple replicas for failover?
- PodDisruptionBudget to prevent accidental downtime?
2. Manifest Structure & Ordering
Manifests in <project>.yaml follow this order (separated by ---):
# 1. Namespace (if creating a new one)
apiVersion: v1
kind: Namespace
metadata:
name: multicloud-<project>
---
# 2. Secrets (credentials, API keys, oauth2 config)
apiVersion: v1
kind: Secret
metadata:
name: <project>-secrets
namespace: multicloud-<project>
---
# 3. ConfigMaps (non-sensitive config)
apiVersion: v1
kind: ConfigMap
metadata:
name: <project>-config
namespace: multicloud-<project>
---
# 4. Deployment / StatefulSet / DaemonSet (workload)
apiVersion: apps/v1
kind: Deployment
metadata:
name: <project>-<component>
namespace: multicloud-<project>
---
# 5. Service (internal + external ports)
apiVersion: v1
kind: Service
metadata:
name: <project>-<component>
namespace: multicloud-<project>
---
# 6. PodDisruptionBudget (optional, for HA)
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: <project>-<component>
namespace: multicloud-<project>
---
# 7. Ingress (public/mTLS endpoints)
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: <project>-<component>
namespace: multicloud-<project>
3. Field-by-Field Guide
Do NOT set a raw
cpu:request/limit. This platform schedules CPU by benchmarked capability via themulticloud.io/cpu-unitsresource, and an admission webhook fills in the actualcpurequest/limit for you. If you setcpu:yourself (e.g. thecpu: 100m/cpu: 500mshown in the examples below), the webhook skips the pod and your capability-based scheduling is silently lost. Setmulticloud.io/cpu-unitsand memory; leavecpuunset. See cpu-units-user-guide.md. (Thecpu:values that remain in the examples below are illustrative of the old low-level shape only.)
Deployment / StatefulSet
apiVersion: apps/v1
kind: Deployment # or StatefulSet for databases
metadata:
name: <project>-<component> # descriptive, includes project
namespace: multicloud-<project>
labels:
app: <project>-<component> # used in selectors, logs, dashboards
tier: backend # optional: frontend, backend, worker
version: v1 # optional: for canary deploys
spec:
replicas: 2 # 1 = single instance, 2+ = HA
strategy:
type: RollingUpdate # gradual pod replacement
rollingUpdate:
maxUnavailable: 0 # keep serving during updates
maxSurge: 1 # one extra pod during update
selector:
matchLabels:
app: <project>-<component> # must match template.metadata.labels
template:
metadata:
labels:
app: <project>-<component>
spec:
# Pod-level security baseline
securityContext:
runAsNonRoot: true # non-root user (1001 typical)
runAsUser: 1001
runAsGroup: 1001
fsGroup: 1001
seccompProfile:
type: RuntimeDefault
# For HA: spread replicas across nodes
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution: # soft (preferred)
- labelSelector:
matchExpressions:
- key: app
operator: In
values: [<project>-<component>]
topologyKey: kubernetes.io/hostname
weight: 100
# Containers
containers:
- name: <component> # e.g. "backend", "frontend"
image: <registry>/<project>:<tag>
imagePullPolicy: Always # always fetch latest in dev
# Port matching Service.ports[].targetPort
ports:
- containerPort: 8080
name: http
protocol: TCP
# Environment from Secret (never inline credentials!)
env:
- name: APP_NAME
value: <project>-<component>
- name: ENVIRONMENT
value: production
- name: LOG_LEVEL
value: info
# From Secret: NEVER inline sensitive data
- name: DATABASE_PASSWORD
valueFrom:
secretKeyRef:
name: <project>-secrets
key: db-password
# Bulk Secret/ConfigMap as env
envFrom:
- secretRef:
name: <project>-secrets
- configMapRef:
name: <project>-config
# Health checks
readinessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 10
periodSeconds: 5
failureThreshold: 3
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 30
periodSeconds: 10
failureThreshold: 3
# Resource guarantees
resources:
requests: # minimum guaranteed
cpu: 100m
memory: 256Mi
limits: # hard cap (OOMKilled if exceeded)
memory: 512Mi
# no CPU limit (burstable)
# Persistent storage (if needed)
volumeMounts:
- name: data
mountPath: /data
# Sidecar example: oauth2-proxy
- name: oauth2-proxy
image: quay.io/oauth2-proxy/oauth2-proxy:v7.15.2
# ... (see [Step 3](#step-3--add-the-sidecar-to-your-deployment) in k3s-oauth.md)
# Shared volumes
volumes:
- name: data
emptyDir: {} # ephemeral, cleared on pod restart
# For S3 artifacts
- name: shared
emptyDir: {}
# Init containers (run once before main containers)
initContainers:
- name: download-config
image: amazon/aws-cli:latest
command:
- sh
- -c
- aws s3 cp s3://bucket/config.json /shared/config.json
env:
- name: AWS_ACCESS_KEY_ID
valueFrom:
secretKeyRef:
name: <project>-secrets
key: aws-access-key-id
- name: AWS_SECRET_ACCESS_KEY
valueFrom:
secretKeyRef:
name: <project>-secrets
key: aws-secret-access-key
- name: AWS_DEFAULT_REGION
value: us-east-1
- name: AWS_USE_DUALSTACK_ENDPOINT
value: "true" # IPv6 across clouds
volumeMounts:
- name: shared
mountPath: /shared
Service
apiVersion: v1
kind: Service
metadata:
name: <project>-<component> # matches Deployment name
namespace: multicloud-<project>
labels:
app: <project>-<component> # same label as Deployment
spec:
type: ClusterIP # internal-only by default
selector:
app: <project>-<component> # routes to matching pods
ports:
# Public-facing port (through Ingress)
- name: http
port: 80
targetPort: 8080 # pod's containerPort
protocol: TCP
# OAuth2-proxy sidecar (if applicable)
- name: auth
port: 4180
targetPort: 4180
# Metrics (internal only)
- name: metrics
port: 9090
targetPort: 9090
Ingress (Public)
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: <project>-<component>-public
namespace: multicloud-<project>
annotations:
# Force HTTPS, get Let's Encrypt cert
cert-manager.io/cluster-issuer: letsencrypt-http01
spec:
ingressClassName: traefik
# TLS certificate
tls:
- hosts:
- app.example.com # your domain
secretName: <project>-tls # auto-managed by cert-manager
# Routing rules
rules:
- host: app.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: <project>-<component>
port:
name: http
Per-record DNS overrides
The scheduler publishes a public A/AAAA record for every non-wildcard host in
spec.rules[].host and points it at the cluster's worker-node IPs. The DNS
provider (Cloudflare, Route53, …) is picked once per cluster, and its
default behavior lives in the Dns.configuration JSONB column — e.g.
Cloudflare zones default to a specific proxied setting.
To override that default for a single Ingress, annotate it with
multicloud.io/dns-config.<key>: <value>. The key namespace mirrors
Dns.configuration, so any provider-specific knob is available without a
new annotation. The override applies to every host on that Ingress — if
you need different settings per host, split them into separate Ingress
objects.
Cloudflare example — turn off the orange-cloud proxy for an mTLS or end-to-end-TLS endpoint that must hit the worker node directly:
metadata:
annotations:
multicloud.io/dns-config.proxied: "false"
Values are always strings (Kubernetes annotation values are strings); the provider parses to its expected type. Route53 and other providers without the named key silently ignore it.
Ingress (Protected with OAuth2)
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: <project>-<component>-protected
namespace: multicloud-<project>
spec:
ingressClassName: traefik
tls:
- hosts: [admin.example.com]
secretName: multicloud-tls # platform cert
rules:
- host: admin.example.com
http:
paths:
# All paths go through oauth2-proxy (port: auth)
- path: /
pathType: Prefix
backend:
service:
name: <project>-<component>
port:
name: auth # sidecar on :4180
PodDisruptionBudget (for HA)
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: <project>-<component>
namespace: multicloud-<project>
spec:
minAvailable: 1 # at least 1 pod running
selector:
matchLabels:
app: <project>-<component>
# OR: maxUnavailable: 1 # at most 1 pod disrupted
Secret (Credentials)
apiVersion: v1
kind: Secret
metadata:
name: <project>-secrets
namespace: multicloud-<project>
type: Opaque
stringData:
# Database
db-host: postgres.example.com
db-port: "5432"
db-name: appdb
db-user: appuser
db-password: <random-long-password>
# AWS / Cloud
aws-access-key-id: AKIA...
aws-secret-access-key: <key>
# API Keys
api-key: sk_live_...
# OAuth2-proxy config (if using sidecar)
client-id: my-client
client-secret: <from-keycloak>
cookie-secret: <32-byte-random> # openssl rand -base64 32
Security note: In production, use sealed-secrets or external-secrets operator instead of inline YAML.
4. Common Patterns
Single-Instance Stateless Web App
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
namespace: multicloud-myapp
spec:
replicas: 1 # single instance
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: app
image: myregistry/myapp:v1.0
ports:
- containerPort: 3000
resources:
requests:
cpu: 100m
memory: 256Mi
limits:
memory: 512Mi
---
apiVersion: v1
kind: Service
metadata:
name: myapp
namespace: multicloud-myapp
spec:
selector:
app: myapp
ports:
- port: 80
targetPort: 3000
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: myapp
namespace: multicloud-myapp
annotations:
cert-manager.io/cluster-issuer: letsencrypt-http01
spec:
ingressClassName: traefik
tls:
- hosts: [myapp.example.com]
secretName: myapp-tls
rules:
- host: myapp.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: myapp
port:
number: 80
High-Availability App (2+ Replicas)
Add to Deployment:
spec:
replicas: 2 # or more
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchLabels:
app: <project>-<component>
topologyKey: kubernetes.io/hostname
weight: 100
---
# PDB ensures at least 1 stays up
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: <project>-<component>
namespace: multicloud-<project>
spec:
minAvailable: 1
selector:
matchLabels:
app: <project>-<component>
Backend + Frontend (SPA with SSR)
# Frontend pod uses Service discovery to talk to backend
env:
- name: BACKEND_URL
value: http://myapp-backend:80 # in-cluster Service DNS
---
# Ingress routes both under same domain
rules:
- host: app.example.com
http:
paths:
- path: /api # backend routes
pathType: Prefix
backend:
service:
name: myapp-backend
port:
name: http
- path: / # frontend (catch-all)
pathType: Prefix
backend:
service:
name: myapp-frontend
port:
name: http
With OAuth2 (Protected Admin Path)
See k3s-oauth.md Step 2–5 for complete pattern. Summary:
- Create OIDC client in Keycloak → get client-id, client-secret
- Create Secret with credentials + cookie-secret
- Add oauth2-proxy sidecar to Deployment
- Expose Service ports:
http(direct) +auth(sidecar) - Create two Ingresses:
protected→ auth port,public→ http port
Example: a frontend and backend behind oauth2-proxy, in one manifest.
Stateful Workloads (use external storage — no in-cluster PVCs)
This cluster provides NO StorageClass. Every node is spot/preemptible, so node-pinned storage strands pods on rotation.
PersistentVolumeClaims,StatefulSet.volumeClaimTemplates, andStorageClasscreation are rejected cluster-wide by theno-persistent-storageValidatingAdmissionPolicy. For durable state, point your app at external managed storage — managed PostgreSQL (e.g.db.multicloud.io) or S3-compatible object storage. UseemptyDironly for rebuildable cache/WAL that is safe to lose on reschedule. The example below usesemptyDirto stay admissible; do not treat it as durable.
apiVersion: apps/v1
kind: StatefulSet # preserves pod identity (volume is NOT durable — see note above)
metadata:
name: myapp-postgres
namespace: multicloud-myapp
spec:
serviceName: myapp-postgres # headless Service for pod DNS
replicas: 1
selector:
matchLabels:
app: myapp-postgres
template:
metadata:
labels:
app: myapp-postgres
spec:
containers:
- name: postgres
image: postgres:15-alpine
ports:
- containerPort: 5432
env:
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: myapp-secrets
key: db-password
volumeMounts:
- name: data
mountPath: /var/lib/postgresql/data
# emptyDir ONLY — data is lost on pod reschedule / node rotation.
# volumeClaimTemplates would be rejected by the no-persistent-storage
# admission policy. For a real database, drop this StatefulSet and point
# the app at external managed PostgreSQL (e.g. db.multicloud.io) instead.
volumes:
- name: data
emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
name: myapp-postgres
namespace: multicloud-myapp
spec:
clusterIP: None # headless Service
selector:
app: myapp-postgres
ports:
- port: 5432
Worker Deployment (Async Jobs)
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-worker
namespace: multicloud-myapp
spec:
replicas: 2 # multiple workers
selector:
matchLabels:
app: myapp-worker
tier: worker
template:
metadata:
labels:
app: myapp-worker
tier: worker
spec:
containers:
- name: worker
image: myregistry/myapp-worker:v1.0
command:
- python
- worker.py # runs indefinitely, consumes queue
env:
- name: QUEUE_URL
value: rabbitmq://rabbitmq:5672
- name: QUEUE_NAME
value: tasks
resources:
requests:
cpu: 500m # workers are CPU-intensive
memory: 1Gi
limits:
memory: 2Gi
# Optional: spread workers across nodes for resilience
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchLabels:
app: myapp-worker
topologyKey: kubernetes.io/hostname
weight: 100
5. Manifest Creation Checklist
After writing your manifest, verify:
-
Naming
- All resources use descriptive names (
<project>-<component>) - Namespace follows
multicloud-<project>convention - Labels match across Deployment → Service → PDB → Ingress
- All resources use descriptive names (
-
Namespace & Isolation
- Correct namespace in every resource
- No cross-namespace references (except platform secrets like
multicloud-tls) - RBAC not needed (namespace isolation sufficient for multi-tenant)
-
Secrets
- No credentials in
env:values (usesecretKeyRef) - No passwords in Ingress, ConfigMap, or git-tracked files
- Secret referenced by Deployment exists in namespace
- No credentials in
-
Networking
- Service selector matches Deployment labels
- Ingress backend service name matches Service name
- Port numbers don't conflict
- TLS secretName matches cert-manager or pre-provisioned Secret
-
High Availability (if replicas > 1)
-
podAntiAffinitypresent to spread across nodes -
PodDisruptionBudgetpresent to prevent simultaneous evictions - Health checks (readiness + liveness probes) configured
-
-
Resources
-
requestsset (CPU, memory) -
limitsset for memory (prevents OOMKilled surprises) - Realistic for your app (test locally first)
-
-
Ingress
- Public apps use
cert-manager.io/cluster-issuer: letsencrypt-http01 - OAuth2 apps follow k3s-oauth.md pattern (protected + public Ingress)
- Domain names are correct
- Public apps use
6. Deployment & Verification
Apply the Manifest
# Dry-run first (no actual changes)
kubectl apply -f <project>.yaml --dry-run=client -o yaml
# Actually apply
kubectl apply -f <project>.yaml
# Watch rollout
kubectl -n multicloud-<project> rollout status deploy/<project>-<component>
Verify Deployment
# Check pods are running
kubectl -n multicloud-<project> get pods -o wide
# Check pod logs
kubectl -n multicloud-<project> logs -l app=<project>-<component> --tail=100
# Check Service is exposed
kubectl -n multicloud-<project> get svc <project>-<component>
# Check Ingress routes are wired
kubectl -n multicloud-<project> describe ingress <project>-<component>
# Test endpoint (public)
curl -I https://app.example.com/
# Test endpoint (mTLS)
curl -kI --cert client.crt --key client.key https://app.example.com/
# Check Secrets are mounted
kubectl -n multicloud-<project> exec pod/<project>-<component>-xxx -- env | grep DB
Troubleshooting
| Symptom | Debug Command | Likely Cause |
|---|---|---|
Pod stuck Pending |
kubectl describe pod -n ns pod-name |
Resource request too high, node label mismatch |
Pod CrashLoopBackOff |
kubectl logs -n ns pod-name |
App error, missing env var, bad image |
| 502 Bad Gateway from Ingress | kubectl describe ingress -n ns ingress-name |
Service not found, port mismatch |
| Pod can't reach database | kubectl exec pod-name -- ping <db-host> |
hostNetwork needed? Firewall? DNS? |
| Liveness probe failing | kubectl describe pod → events |
App not responding on health check endpoint |
7. Best Practices
Naming & Organization
- Use hyphens in names, not underscores (
my-app, notmy_app) - Project prefix everything: Even on a quiet cluster,
backendis ambiguous. Usemyapp-backend - One manifest per project:
myapp.yamlcontains Deployment, Service, Ingress, Secrets, etc.
Isolation & Security
- Namespace = tenant: One namespace per client/project. No cross-namespace communication except for platform services.
- Never inline secrets: Use
secretKeyRef, nevervalue: password123 - Resource limits: Always set memory
limitsto avoid OOMKilled surprises. CPU limits optional (burstable). - Security context: Run as non-root, drop capabilities, use seccomp.
High Availability
- replicas ≥ 2: For production workloads, always run 2+ instances
- podAntiAffinity: Spread replicas across nodes
- PodDisruptionBudget: Protect against accidental simultaneous pod evictions
- Health checks: Readiness (when to route traffic) + Liveness (when to restart)
Networking
- Use Service DNS for in-cluster communication:
http://service-name:port - Ingress for public endpoints: Traefik handles TLS, DNS, routing
- Split Ingress for OAuth2: Protected path → sidecar, public path → app
- Avoid hostNetwork unless absolutely necessary (IPv4 reachability, privileged ports)
Configuration Management
- Secrets for credentials: Database passwords, API keys, auth tokens
- ConfigMap for non-sensitive config: Log levels, feature flags, URLs
- Environment variables for runtime config
- Volume mounts for files (certificates, configs too large for env)
8. Reference Examples
- Simple stateless app: frontend + backend with oauth2-proxy in one manifest
- OAuth2 setup: k3s-oauth.md — Keycloak OIDC client creation and sidecar pattern
9. When to Use What
| Need | Pattern | Example |
|---|---|---|
| Simple web app | Deployment (replicas: 1) + Service + Ingress | Next.js, Flask, Node.js server |
| Scalable web app | Deployment (replicas: 2+) + PDB + anti-affinity | Load-balanced API |
| Database | StatefulSet + external managed PG / object storage (no PVC — rejected cluster-wide) | PostgreSQL, MySQL, MongoDB |
| Long-running worker | Deployment (tier: worker) | Celery task consumer, queue processor |
| Per-node agent | DaemonSet | Monitoring, log shipping, CNI |
| Admin endpoints | Ingress (oauth2-proxy sidecar) | Strapi, Hasura, internal dashboards |
| Public API | Ingress (no auth) | REST API, webhook endpoints |
| Batch job | Job or CronJob | Database backups, data exports |
10. Advanced: Multi-Component Apps
For apps with frontend, backend, database, worker:
myapp.yaml
# Namespace
kind: Namespace
metadata:
name: multicloud-myapp
---
# Database Secret
kind: Secret
metadata:
name: myapp-secrets
---
# Database
kind: StatefulSet
metadata:
name: myapp-postgres
---
# Backend API
kind: Deployment
metadata:
name: myapp-backend
---
# Backend Service
kind: Service
metadata:
name: myapp-backend
---
# Frontend (calls backend via Service DNS)
kind: Deployment
metadata:
name: myapp-frontend
---
# Frontend Service
kind: Service
metadata:
name: myapp-frontend
---
# Async worker
kind: Deployment
metadata:
name: myapp-worker
---
# Public Ingress (frontend)
kind: Ingress
metadata:
name: myapp-public
---
# PDB for frontend
kind: PodDisruptionBudget
metadata:
name: myapp-frontend
---
# PDB for worker
kind: PodDisruptionBudget
metadata:
name: myapp-worker
One file, one namespace, clear organization. Deploy with: kubectl apply -f myapp.yaml