Skip to content

Instantly share code, notes, and snippets.

@jpallari
Last active August 15, 2022 05:27
Show Gist options
  • Save jpallari/1d6b5dfbc6660021557ad1e56029e48a to your computer and use it in GitHub Desktop.
Save jpallari/1d6b5dfbc6660021557ad1e56029e48a to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# This script deploys the given manifest,
# tracks the deployment, and rolls back on failure.
#
# First execute this with "myapp.yaml" and then try it with "myapp.failing.yaml"
#
MANIFEST_PATH=$1
DEPLOYMENT_NAME=myapp
if [ -n "$2" ]; then
DEPLOYMENT_NAME=$2
fi
kubectl apply -f "$MANIFEST_PATH"
if ! kubectl rollout status deployment "$DEPLOYMENT_NAME"; then
echo "Rolling back deployment!" >&2
kubectl rollout undo deployment "$DEPLOYMENT_NAME"
kubectl rollout status deployment myapp
exit 1
fi
# Example hello world app deployment that fails
# because of an incorrectly configured readiness probe.
#
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: myapp
name: myapp
spec:
replicas: 3
progressDeadlineSeconds: 30
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- image: polarsquad/hello-world-app:master
name: hello-world
ports:
- containerPort: 3000
readinessProbe:
httpGet:
path: /this-does-not-exist
port: 3000
# Example hello world app deployment
# including a readiness probe and a progress deadline.
#
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: myapp
name: myapp
spec:
replicas: 3
progressDeadlineSeconds: 30
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- image: polarsquad/hello-world-app:master
name: hello-world
ports:
- containerPort: 3000
readinessProbe:
httpGet:
path: /
port: 3000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment