writing-skills
writing-skills
Use when creating new skills, editing existing skills, or verifying skills work before deployment
kubernetes-deploymentImplements apps/v1 Deployment YAML manifests with rolling update strategies, replica scaling, and rollback procedures for stateless application workloads.
Independent GitHub snapshot ยท Automated classification ยท Original documentation governs
Implements apps/v1 Deployment YAML manifests for stateless application workloads with rolling update strategies, replica management, and controlled rollback procedures. When loaded, the model generates production-grade Deployment resources with proper strategy configuration, health probes, and rollout monitoring.
apps/v1 API version โ never extensions/v1beta1 or apps/v1beta1strategy.type: RollingUpdate with explicit maxSurge and maxUnavailableminReadySeconds to prevent premature rollout of next batchlivenessProbe and readinessProbe with appropriate initial delaysstrategy.type: Recreate for zero-downtime deploymentskubectl rollout status before proceedingUse this skill when:
Avoid this skill for:
kubernetes-statefulset insteadkubernetes-statefulset insteadkubernetes-persistentvolume with StatefulSetDetermine Deployment Requirements โ Identify replica count, container image, ports, and resource limits. Checkpoint: Verify the application is stateless (no local disk writes, no sticky sessions) โ if not, StatefulSet is required.
Define Pod Template Spec โ Create the spec.template.spec with containers, ports, environment variables, volume mounts, and security context. Checkpoint: Every container must have a livenessProbe and readinessProbe configured.
Configure Rolling Update Strategy โ Set strategy.type: RollingUpdate with rollingUpdate.maxSurge and rollingUpdate.maxUnavailable. Checkpoint: maxSurge and maxUnavailable must sum to no more than 50% of replicas for safe scaling, unless explicitly tolerating temporary excess.
Set Replicas and Selector โ Define spec.replicas and a spec.selector.matchLabels that matches the pod template labels. Checkpoint: Selector labels must exactly match spec.template.metadata.labels โ mismatched selectors cause deployment rejection.
Create and Validate Manifest โ Apply the manifest with kubectl apply -f deployment.yaml --dry-run=client then kubectl apply -f deployment.yaml. Checkpoint: Run kubectl rollout status deploy/<name> and verify all pods reach Ready state.
Plan Rollback Path โ Keep the previous revision history available. Use kubectl rollout undo deploy/<name> if the new version shows errors. Checkpoint: Monitor pod logs and metrics during the first 60 seconds after each rollout.
A complete Deployment with rolling update strategy, health probes, resource limits, and proper labeling for service discovery.
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-frontend
namespace: production
labels:
app: web-frontend
tier: frontend
version: v2.1.0
spec:
replicas: 3
revisionHistoryLimit: 5
selector:
matchLabels:
app: web-frontend
tier: frontend
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
minReadySeconds: 30
template:
metadata:
labels:
app: web-frontend
tier: frontend
version: v2.1.0
spec:
terminationGracePeriodSeconds: 30
securityContext:
runAsNonRoot: true
runAsUser: 1000
fsGroup: 1000
containers:
- name: web-frontend
image: registry.example.com/web-frontend:2.1.0
ports:
- containerPort: 8080
protocol: TCP
name: http
env:
- name: APP_ENV
value: production
- name: LOG_LEVEL
valueFrom:
configMapKeyRef:
name: app-config
key: log-level
resources:
requests:
cpu: 250m
memory: 256Mi
limits:
cpu: 500m
memory: 512Mi
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 15
periodSeconds: 10
timeoutSeconds: 3
failureThreshold: 3
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
timeoutSeconds: 2
failureThreshold: 3
volumeMounts:
- name: config-volume
mountPath: /etc/app/config
readOnly: true
volumes:
- name: config-volume
configMap:
name: app-config
Configuring the rolling update strategy incorrectly can cause service downtime or excessive resource usage.
# โ BAD โ default strategy causes unpredictable rollout behavior
# maxSurge and maxUnavailable are unset, using defaults (25%/25%) which
# may take down too many pods or spin up too many simultaneously.
strategy:
type: RollingUpdate
# โ BAD โ Recreate strategy causes full downtime on every deployment
strategy:
type: Recreate
# โ
GOOD โ explicit RollingUpdate with conservative safety parameters
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1 # Only add 1 extra pod during rollout
maxUnavailable: 0 # Never reduce below desired replica count
minReadySeconds: 30 # Wait 30s after pod becomes ready before proceeding
# โ
GOOD โ aggressive strategy for development environments with low risk
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 2
maxUnavailable: 1
minReadySeconds: 5
Programmatic rollback logic using kubectl commands and manifest versioning.
# Rollback to previous revision
# kubectl rollout undo deployment/web-frontend -n production
# Rollback to a specific revision (if history is preserved)
# kubectl rollout undo deployment/web-frontend -n production --to-revision=2
# View rollout history
# kubectl rollout history deployment/web-frontend -n production
# View details of a specific revision
# kubectl rollout history deployment/web-frontend -n production --revision=3
# View rollout status after apply or undo
# kubectl rollout status deployment/web-frontend -n production --timeout=120s
# Pause and resume rollouts for manual approval gates
# kubectl rollout pause deployment/web-frontend -n production
# kubectl rollout resume deployment/web-frontend -n production
def check_deployment_healthy(name: str, namespace: str, timeout_seconds: int = 120) -> bool:
"""Check if a Deployment rollout completed successfully.
Uses kubectl rollout status to verify all pods are Ready.
Returns True if healthy, False if timeout or failure detected.
Args:
name: Deployment name.
namespace: Kubernetes namespace.
timeout_seconds: Maximum time to wait for rollout.
Returns:
True if rollout completed successfully, False otherwise.
"""
import subprocess
try:
result = subprocess.run(
["kubectl", "rollout", "status", f"deploy/{name}",
"-n", namespace, f"--timeout={timeout_seconds}s"],
capture_output=True, text=True, timeout=timeout_seconds + 10
)
return result.returncode == 0 and "successfully rolled out" in result.stdout
except subprocess.TimeoutExpired:
return False
except FileNotFoundError:
return False
apps/v1 API version โ never extensions/v1beta1 or apps/v1beta1 (both are removed in Kubernetes 1.16+)strategy.type: RollingUpdate with concrete maxSurge and maxUnavailable valueslivenessProbe and readinessProbe on every container โ never rely on defaultsresources.requests and resources.limits on every container for proper scheduling and QoSterminationGracePeriodSeconds (โฅ 30s for graceful shutdown) in the pod specspec.selector.matchLabels exactly to spec.template.metadata.labelsrevisionHistoryLimit: 5 to preserve rollout history for rollbacksminReadySeconds (โฅ 15s) to ensure pods are truly ready before the next batch startsstrategy.type: Recreate for production stateless workloads โ it causes full downtimelivenessProbe or readinessProbe โ the node cannot detect unhealthy pods otherwisemaxUnavailable to the total replica count โ this allows complete outage during rolloutlatest tag in production images โ always pin to a specific image digest or semver tagterminationGracePeriodSeconds: 0 โ in-flight requests will be dropped on pod deletionWhen implementing a Kubernetes Deployment, produce the following:
apps/v1 Deployment manifest with metadata, spec.replicas, spec.strategy, spec.selector, and spec.template fully defined.maxSurge, maxUnavailable, and minReadySeconds values relative to the replica count.| Skill | Purpose |
|---|---|
kubernetes-services-management | Expose the Deployment via ClusterIP, NodePort, or LoadBalancer service |
kubernetes-ingress | Route external HTTP/HTTPS traffic to the Deployment's service |
kubernetes-configmap | Inject configuration data into the Deployment via env vars or volume mounts |
kubernetes-statefulset | Deploy stateful applications that need stable network identities and persistent storage |
Authoritative documentation links for this skill's domain. The model follows markdown links at load time to resolve external references and inline content.