Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Deploy and manage Kubernetes workloads: manifests, RBAC, Helm charts, service mesh, GitOps, and troubleshooting.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/workloads.md
1# Kubernetes Workloads23## Deployment Pattern45```yaml6apiVersion: apps/v17kind: Deployment8metadata:9name: web-app10namespace: production11labels:12app: web-app13tier: frontend14spec:15replicas: 316revisionHistoryLimit: 1017strategy:18type: RollingUpdate19rollingUpdate:20maxSurge: 121maxUnavailable: 022selector:23matchLabels:24app: web-app25template:26metadata:27labels:28app: web-app29tier: frontend30version: v1.2.031annotations:32prometheus.io/scrape: "true"33prometheus.io/port: "8080"34spec:35serviceAccountName: web-app-sa36securityContext:37runAsNonRoot: true38runAsUser: 100039fsGroup: 200040containers:41- name: app42image: myregistry.io/web-app:v1.2.043imagePullPolicy: IfNotPresent44ports:45- name: http46containerPort: 808047protocol: TCP48env:49- name: ENVIRONMENT50value: production51- name: DB_HOST52valueFrom:53configMapKeyRef:54name: app-config55key: database.host56- name: DB_PASSWORD57valueFrom:58secretKeyRef:59name: app-secrets60key: db-password61resources:62requests:63cpu: 100m64memory: 128Mi65limits:66cpu: 500m67memory: 512Mi68livenessProbe:69httpGet:70path: /health71port: http72initialDelaySeconds: 3073periodSeconds: 1074timeoutSeconds: 575failureThreshold: 376readinessProbe:77httpGet:78path: /ready79port: http80initialDelaySeconds: 1081periodSeconds: 582timeoutSeconds: 383failureThreshold: 284volumeMounts:85- name: config86mountPath: /etc/config87readOnly: true88- name: cache89mountPath: /var/cache90volumes:91- name: config92configMap:93name: app-config94- name: cache95emptyDir: {}96```9798## StatefulSet Pattern99100```yaml101apiVersion: apps/v1102kind: StatefulSet103metadata:104name: postgres105namespace: database106spec:107serviceName: postgres-headless108replicas: 3109podManagementPolicy: OrderedReady110updateStrategy:111type: RollingUpdate112selector:113matchLabels:114app: postgres115template:116metadata:117labels:118app: postgres119spec:120serviceAccountName: postgres-sa121securityContext:122runAsUser: 999123fsGroup: 999124containers:125- name: postgres126image: postgres:15-alpine127ports:128- name: postgres129containerPort: 5432130env:131- name: POSTGRES_PASSWORD132valueFrom:133secretKeyRef:134name: postgres-secrets135key: password136- name: PGDATA137value: /var/lib/postgresql/data/pgdata138resources:139requests:140cpu: 500m141memory: 1Gi142limits:143cpu: 2000m144memory: 4Gi145volumeMounts:146- name: data147mountPath: /var/lib/postgresql/data148livenessProbe:149exec:150command:151- pg_isready152- -U153- postgres154initialDelaySeconds: 30155periodSeconds: 10156readinessProbe:157exec:158command:159- pg_isready160- -U161- postgres162initialDelaySeconds: 10163periodSeconds: 5164volumeClaimTemplates:165- metadata:166name: data167spec:168accessModes: ["ReadWriteOnce"]169storageClassName: fast-ssd170resources:171requests:172storage: 50Gi173```174175## DaemonSet Pattern176177```yaml178apiVersion: apps/v1179kind: DaemonSet180metadata:181name: node-exporter182namespace: monitoring183spec:184selector:185matchLabels:186app: node-exporter187updateStrategy:188type: RollingUpdate189rollingUpdate:190maxUnavailable: 1191template:192metadata:193labels:194app: node-exporter195spec:196hostNetwork: true197hostPID: true198serviceAccountName: node-exporter-sa199tolerations:200- effect: NoSchedule201operator: Exists202containers:203- name: node-exporter204image: prom/node-exporter:latest205args:206- --path.procfs=/host/proc207- --path.sysfs=/host/sys208- --collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)209ports:210- name: metrics211containerPort: 9100212protocol: TCP213resources:214requests:215cpu: 50m216memory: 64Mi217limits:218cpu: 200m219memory: 128Mi220volumeMounts:221- name: proc222mountPath: /host/proc223readOnly: true224- name: sys225mountPath: /host/sys226readOnly: true227volumes:228- name: proc229hostPath:230path: /proc231- name: sys232hostPath:233path: /sys234```235236## Job Pattern237238```yaml239apiVersion: batch/v1240kind: Job241metadata:242name: db-migration-20231214243namespace: production244spec:245backoffLimit: 3246ttlSecondsAfterFinished: 3600247template:248metadata:249labels:250app: db-migration251spec:252restartPolicy: OnFailure253serviceAccountName: migration-sa254containers:255- name: migrate256image: myregistry.io/migrations:v1.2.0257command: ["/bin/sh", "-c"]258args:259- |260echo "Starting migration..."261/app/migrate up262echo "Migration complete"263env:264- name: DATABASE_URL265valueFrom:266secretKeyRef:267name: db-secrets268key: connection-string269resources:270requests:271cpu: 100m272memory: 128Mi273limits:274cpu: 500m275memory: 512Mi276```277278## CronJob Pattern279280```yaml281apiVersion: batch/v1282kind: CronJob283metadata:284name: backup-database285namespace: production286spec:287schedule: "0 2 * * *" # Daily at 2 AM288timeZone: "America/New_York"289successfulJobsHistoryLimit: 3290failedJobsHistoryLimit: 1291concurrencyPolicy: Forbid292jobTemplate:293spec:294backoffLimit: 2295ttlSecondsAfterFinished: 86400296template:297metadata:298labels:299app: backup300spec:301restartPolicy: OnFailure302serviceAccountName: backup-sa303containers:304- name: backup305image: myregistry.io/backup-tool:latest306command: ["/usr/local/bin/backup.sh"]307env:308- name: S3_BUCKET309valueFrom:310configMapKeyRef:311name: backup-config312key: s3-bucket313- name: AWS_ACCESS_KEY_ID314valueFrom:315secretKeyRef:316name: backup-secrets317key: aws-access-key318- name: AWS_SECRET_ACCESS_KEY319valueFrom:320secretKeyRef:321name: backup-secrets322key: aws-secret-key323resources:324requests:325cpu: 200m326memory: 256Mi327limits:328cpu: 1000m329memory: 1Gi330volumeMounts:331- name: backup-volume332mountPath: /backup333volumes:334- name: backup-volume335emptyDir:336sizeLimit: 10Gi337```338339## Init Containers340341```yaml342spec:343initContainers:344- name: wait-for-db345image: busybox:latest346command: ['sh', '-c']347args:348- |349until nc -z postgres-service 5432; do350echo "Waiting for database..."351sleep 2352done353echo "Database is ready"354- name: migrate-schema355image: myregistry.io/migrations:latest356command: ["/app/migrate", "up"]357env:358- name: DATABASE_URL359valueFrom:360secretKeyRef:361name: db-secrets362key: url363containers:364- name: app365image: myregistry.io/app:latest366```367368## Best Practices3693701. **Resource Management**: Always set requests and limits3712. **Health Checks**: Include both liveness and readiness probes3723. **Security**: Use non-root users, read-only filesystems when possible3734. **Labels**: Consistent labeling for organization and selection3745. **Update Strategy**: Choose appropriate strategy (RollingUpdate, Recreate)3756. **Service Accounts**: Never use default, create specific SAs3767. **Image Tags**: Use specific versions, not `latest` in production3778. **Cleanup**: Set TTL for Jobs to auto-cleanup completed pods378