This commit is contained in:
48
examples/cleanup-and-recreate.sh
Executable file
48
examples/cleanup-and-recreate.sh
Executable file
@@ -0,0 +1,48 @@
|
||||
#!/bin/bash
|
||||
# Example script for cleanup and recreation of Kubernetes resources
|
||||
|
||||
set -e
|
||||
|
||||
RESOURCE_NAME="${RESOURCE_NAME:-example-deployment}"
|
||||
NAMESPACE="${NAMESPACE:-default}"
|
||||
|
||||
echo "Starting cleanup and recreation process..."
|
||||
|
||||
# Step 1: Delete old resource
|
||||
echo "Deleting old deployment: ${RESOURCE_NAME}"
|
||||
kubectl delete deployment "${RESOURCE_NAME}" -n "${NAMESPACE}" --ignore-not-found=true
|
||||
|
||||
# Step 2: Wait for complete deletion
|
||||
echo "Waiting for deployment deletion..."
|
||||
kubectl wait --for=delete deployment/"${RESOURCE_NAME}" -n "${NAMESPACE}" --timeout=300s 2>/dev/null || true
|
||||
|
||||
# Step 3: Create new resource from manifest
|
||||
echo "Creating new deployment..."
|
||||
cat <<EOF | kubectl apply -f -
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: ${RESOURCE_NAME}
|
||||
namespace: ${NAMESPACE}
|
||||
spec:
|
||||
replicas: 3
|
||||
selector:
|
||||
matchLabels:
|
||||
app: ${RESOURCE_NAME}
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: ${RESOURCE_NAME}
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx:latest
|
||||
ports:
|
||||
- containerPort: 80
|
||||
EOF
|
||||
|
||||
# Step 4: Wait for new deployment to be ready
|
||||
echo "Waiting for deployment to be ready..."
|
||||
kubectl wait --for=condition=available deployment/"${RESOURCE_NAME}" -n "${NAMESPACE}" --timeout=300s
|
||||
|
||||
echo "Deployment ${RESOURCE_NAME} successfully recreated!"
|
||||
Reference in New Issue
Block a user