Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading Kops #156

Open
ktun95 opened this issue Aug 13, 2024 · 0 comments
Open

Upgrading Kops #156

ktun95 opened this issue Aug 13, 2024 · 0 comments

Comments

@ktun95
Copy link

ktun95 commented Aug 13, 2024

Justfile Recipes for Cluster Operations

This Justfile contains several recipes for managing Kubernetes clusters using Kops:

  1. cluster-setup : Sets up a Kubernetes cluster with Kops version v1.27.1. This recipe includes steps to install Kops, create and validate the cluster, and run the workload recipe.

  2. workload : This recipe is currently a work-in-progress. It creates a Kubernetes Deployment, a Secret, and a ConfigMap. An external request to validate the workload is pending.

  3. cleanup : Deletes the resources created by the workload recipe.

  4. upgrade : Upgrades Kops to higher versions incrementally. For each version, it updates and validates the cluster, then runs the workload and cleanup recipes.

How to Use

To set up a cluster, run just cluster-setup. To upgrade your cluster, run just upgrade.

Known Issues

While upgrading Kops from v1.27.1 to v1.28.7 works without issues, upgrading to v1.29.0 has known problems which are still under diagnosis. I will detail what I know about the issue in a following comment.


For a more detailed and technical explanation, refer to the Justfile code below:

# Justfile
set shell := ["zsh", "-cu"]

cluster-setup: 
  @echo "Setting up cluster" 
  asdf install kops v1.27.1 
  asdf local kops v1.27.1
  if kops get cluster; then \
    kops delete cluster --yes; \
  fi; \
  kops create cluster --zones us-central1-a --yes 
  kops export kubeconfig --admin
  kops validate cluster --wait 10m
  just workload

workload: 
  @echo "Running workload..."
  if ! kubectl apply -f ../configmaps/dictycr-configuration.yml 2>>{{LOG_FILE}}; then \
    echo "Error encountered while running workload" | tee -a {{LOG_FILE}}; \
    exit 1; \
  fi; \
  if ! kubectl apply -f ../secrets/dictycr-secret-dev.yml 2>>{{LOG_FILE}}; then \
    echo "Error encountered while running workload" | tee -a {{LOG_FILE}}; \
    exit 1; \
  fi; \
  if ! kubectl apply -f ../deployments/stockcenter-api-server.yml 2>>{{LOG_FILE}}; then \
    echo "Error encountered while running workload" | tee -a {{LOG_FILE}}; \
    exit 1; \
  fi; \

cleanup: 
  @echo "Running clean up..."
  if ! kubectl delete configmap dictycr-configuration 2>>{{LOG_FILE}}; then \
      echo "Error encountered while running workload" | tee -a {{LOG_FILE}}; \
      exit 1; \
  fi; \
  if ! kubectl delete secret dictycr-secret-dev 2>>{{LOG_FILE}}; then \
      echo "Error encountered while running workload" | tee -a {{LOG_FILE}}; \
      exit 1; \
  fi; \
  if ! kubectl delete deployment stockcenter-api-server 2>>{{LOG_FILE}}; then \
      echo "Error encountered while running workload" | tee -a {{LOG_FILE}}; \
      exit 1; \
  fi; \

# Define the path to the versions file
LOG_FILE := "kops_upgrade_log.txt"
VERSIONS := "v1.27.2 v1.27.3 v1.28.0 v1.28.1 v1.28.2 v1.28.3 v1.28.4 v1.28.5 v1.28.7 v1.29.0 v1.29.2"

# Load the versions into a variable

# Task to upgrade kops versions
upgrade:
  @echo "Starting kops upgrade process..."

  @rm -f {{LOG_FILE}}
  @echo "Log file wiped" 
  @for version in {{VERSIONS}}; do \
      echo "Upgrading to kops version $version..." | tee -a {{LOG_FILE}}; \
      if ! asdf install kops $version 2>>{{LOG_FILE}}; then \
          echo "Error encountered during kops version $version installation" | tee -a {{LOG_FILE}}; \
          exit 1; \
      fi; \
      if ! asdf local kops $version 2>>{{LOG_FILE}}; then \
          echo "Error encountered using kops version $version" | tee -a {{LOG_FILE}}; \
          exit 1; \
      fi; \
      if ! kops update cluster --yes 2>>{{LOG_FILE}}; then \
          echo "Error encountered during kops update with version $version" | tee -a {{LOG_FILE}}; \
          exit 1; \
      fi; \
      if ! kops export kubeconfig --admin 2>>{{LOG_FILE}}; then \
          echo "Error encountered during kubeconfig export with version $version" | tee -a {{LOG_FILE}}; \
          exit 1; \
      fi; \
      if ! kops validate cluster --wait 10m 2>>{{LOG_FILE}}; then \
          echo "Error encountered during cluster validation with version $version" | tee -a {{LOG_FILE}}; \
          exit 1; \
      fi; \
      just workload; \
      just cleanup; \
      echo "Successfully upgraded to kops version $version" | tee -a {{LOG_FILE}}; \
  done

  @echo "Kops upgrade process completed." | tee -a {{LOG_FILE}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant