Skip to content
Snippets Groups Projects

Kubectl Force recreate plugin

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Adphi

    Description

    This kubectl plugin recreates the pods managed by the specified deployment or daemonset.

    Installation:

    curl -s https://gitlab.bertha.cloud/snippets/17/raw > kubectl-force && chmod +x kubectl-force && sudo mv kubectl-force /usr/local/bin/

    Usage:

    kubectl force deploy kube-dns
    Edited
    kubectl-force.sh 681 B
    #!/usr/bin/env bash
    
    # Copyright 2020, The Bertha Cloud Team.
    # Copyright 2017, Z Lab Corporation. All rights reserved.
    # Copyright 2017, Kubernetes scripts contributors
    
    set -e
    
    if [[ $# -lt 2 ]]; then
      echo "Usage: $0 deploy/ds NAME [kubectl options]" >&2
      echo "" >&2
      echo "This script recreates the pods managed by the specified deployment or daemonset." >&2
      exit 1
    fi
    
    function _kubectl() {
      kubectl $@ $kubectl_options
    }
    
    resource="$1"
    deployment="$2"
    updated_at=$(date +%s)
    kubectl_options="${@:3}"
    
    _kubectl patch "$resource" "$deployment" \
      -p "{\"spec\":{\"template\":{\"metadata\":{\"annotations\":{\"force-update.bertha.cloud/updated-at\":\"$updated_at\"}}}}}"
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment