[Reprint] the migration issue after upgrade Chart solve v3 Helm

Migration v3 Chart Helm upgrade issues resolved

Foreword

After Helm v3 release brings many new features and changes to the structure of the system, most notably that deleted Tiller, and improved the upgrade process. In order to make it easier for users to Helm v2 version transferred to Helm v3, Helm maintenance staff also released a plug-in automatically transferred Helm v2 version to Helm v3.

After migrating to Helm v3, you may encounter some cases subsequent upgrade fails, for example, when upgrading attempt to modify StatefulSet the immutable field. In these cases, you can try one of the following methods to solve the problem:

  • Applications built using the backup / restore utility, backup data Helm v2 version, and may restore it to Helm v3 version.
  • Backup persistent volumes in Helm v2 version, then use Kubernetes backup / restore utility Velero , re-deploy them in Helm v3 release.

This tutorial will guide you try both methods.

Prerequisites

  • You have the Kubnetl and Helm Kubernetes cluster v3 installation. This tutorial uses Google Kubernetes Engine (GKE) cluster, you can also use any other Kubernetes.
  • Before you can use Helm v2 already deployed Bitnami Helm Chart, which added to the data, and then use the migration plug-Helm migrated to Helm v3. The following shows the command to perform these tasks, and REPL-PASSWORD PASSWORD which are referenced database and replicate user passwords.
    helm2 repo add bitnami https://charts.bitnami.com/bitnami 
    helm2 install --name postgres bitnami/postgresql \   --set postgresqlPassword=PASSWORD \   --set replication.password=REPL-PASSWORD \    --set replication.slaveReplicas=1 \   --set replication.enabled=true \   --namespace default helm3 plugin install https://github.com/helm/helm-2to3 helm3 2to3 move config helm3 2to3 convert postgres

prompt

This tutorial demonstrates how to use Bitnami PostgreSQL Helm chart resolved after the migration upgrade issues. However, for other Bitnami Helm Chart, also can follow the same method, but note that some of the following warning.

In this tutorial, helm2 refers Helm v2 CLI, helm3 refers Helm v3 CLI.

Method 1: Use the built-in application tool up and restore data

Use the application's built-in backup / restore feature to back up data Helm v2 version, and then restore the data in the new v3 release of Helm. This method is only applicable to a built-in backup / restore application functionality.

Step 1: Use the built-in backup data tool PostgreSQL

The first step, data backup PostgreSQL version is running in. Proceed as follows:

  • Get PostgreSQL Password:
    export POSTGRES_PASSWORD=$(kubectl get secret --namespace default postgres-postgresql -o jsonpath="{.data.postgresql-password}" | base64 --decode)
  • PostgreSQL port forwarding service:
    kubectl port-forward --namespace default svc/postgres-postgresql 5432:5432 &
  • Use PostgreSQL pg_dumpall tool to back up the contents of all of the database to a file. If this tool is not installed on your system, use Bitnami the PostgreSQL Docker vessel image (comprising the tool and other tools PostgreSQL clients) perform a backup, as follows:
    docker run --rm --name postgresql -e "PGPASSWORD=$POSTGRES_PASSWORD" --net="host" bitnami/postgresql:latest pg_dumpall -h 127.0.0.1 -U postgres > all.sql

    Here, - net parameter allows Docker containers can use the host network stack, thereby gaining access to the port forwarding. The pg_dumpall command to connect to PostgreSQL services, and create a SQL file containing all PostgreSQL database structure and records. Finally, - rm parameters after the pg_dumpall command is completed, remove the container.

  • Stop the service port forwarding.

At the end of this step, you will get a backup file that contains data in PostgreSQL running.

Step 2: restore the data to the new version of the PostgreSQL

The next step is to create an empty PostgreSQL clusters and data recovery to which:

  • Use Helm v3 to create a new version of PostgreSQL in a separate namespace. Alternatively were replaced and the user password and REPL-PASSWORD PASSWORD with the password database.
    kubectl create namespace postgres-new  helm3 repo add bitnami https://charts.bitnami.com/bitnami helm3 install postgres bitnami/postgresql \   --namespace postgres-new \   --set postgresqlPassword=PASSWORD \   --set replication.password=REPL-PASSWORD \   --set replication.slaveReplicas=1 \   --set replication.enabled=true

    prompt

    Two versions of password keeping is very important to avoid authentication issues.

  • Create an environment variable that contains a new version of the password:
    export POSTGRES_PASSWORD=$(kubectl get secret --namespace postgres-new postgres-postgresql -o jsonpath="{.data.postgresql-password}" | base64 --decode)
  • The new version of PostgreSQL forwarding service port:
    kubectl port-forward --namespace postgres-new svc/postgres-postgresql 5432:5432 &
  • Use psql tool to restore the contents of the backup file to the new version. Without this tool on your system, it includes the PostgreSQL Docker Bitnami in the container as a directory backup roll mount, and the use of tools in the container psql client image contents of the backup file into the new cluster, as shown in FIG. :
    docker run --rm --name postgresql -v $(pwd):/app -e "PGPASSWORD=$POSTGRES_PASSWORD" --net="host" bitnami/postgresql:latest psql -h 127.0.0.1 -U postgres -d postgres -f /app/all.sql

    Here, -v parameters of the current directory (containing the backup files) into / app container path. Then, use the psql client tools to connect to PostgreSQL services and perform a backup file in SQL commands to restore data from previous versions. As before, - rm command parameters after the completion of the destruction of the container.

  • Stop the service port forwarding.
  • Connect to the new deployment, and make sure your data has been successfully restored:
    kubectl run postgres-postgresql-client --rm --tty -i --restart='Never' --namespace postgres-new --image docker.io/bitnami/postgresql:11.7.0-debian-10-r9 --env="PGPASSWORD=$POSTGRES_PASSWORD" --command -- psql --host postgres-postgresql -U postgres -d postgres -p 5432

Step 3: Testing the upgrade process (optional)

You should now be able to upgrade to the new version. You can use the following command to test this, where VERSION is replaced with Chart version to be upgraded:

helm3 upgrade --version VERSION postgres bitnami/postgresql \   --namespace postgres-new \   --set postgresqlPassword=PASSWORD \   --set replication.password=REPL-PASSWORD \   --set replication.slaveReplicas=1 \   --set replication.enabled=true

prompt

When the upgrade version, use the same installation parameters.

After confirming that everything is normal, you can choose to delete the previous version.

Method 2: Backup and Restore persistent volumes

Copy lasting volume applications, and use them in the new version again. This method applies only to allow the use of persistent storage volumes statement when installed, and is Velero supported in the Chart. Many Bitnami HelmChart support this feature.

Step 1: Installation Velero

Velero is an open source tool that makes it easy to backup and restore Kubernetes resources. It can be used to backup the entire cluster, or as shown below, can be fine-tuned to back up only a particular resource, such as persistent volume.

  • Follow Velero plug-in setup instructions . If you are using Google Cloud Platform (as described in this tutorial), follow GCP plug-in setup instructions to create a service account and file storage partition and get credentials.
  • Then, by executing the following Velero installation, remember to replace with the name BUCKET-NAME bucket and replaced with SECRET-FILENAME credentials file path:
    velero install --provider gcp --plugins velero/velero-plugin-for-gcp:v1.0.0 --bucket BUCKET-NAME --secret-file SECRET-FILENAME

    After installing Velero, you should see output similar to the following screenshot:

  • Use the following command to check the running Pod to confirm Velero deployment was successful:
    kubectl get pods -n velero

Step 2: Persistence backup roll

Next, use the backup Velero lasting volume.

  • Create a backup of persistent volumes in PostgreSQL is running. The primary and backup will include from the roll.
    velero backup create pgb --include-resources pvc,pv --selector release=postgres
  • Execute the following command, view the contents of the backup and make sure it contains all the necessary resources:
    velero backup describe pgb  --details  
  • To avoid the backup data is overwritten, set the bucket amended to read-only access:
    kubectl patch backupstoragelocation default -n velero --type merge --patch '{"spec":{"accessMode":"ReadOnly"}}'

Step 3: persistent volumes restored to the new version of PostgreSQL

Now, you can restore volume and permanently integrated with the new v3 version Helm.

  • Use Velero, lasting reduction in volume in a separate namespace. Use -namespace-mappings resource parameters can be mapped from the original namespace to the new namespace.
    kubectl create namespace postgres-new     velero restore create --from-backup pgb --namespace-mappings default:postgres-new
  • Confirm persistent volumes have been restored in the new namespace, the primary database node and note the name of the volume:
    kubectl get pvc --namespace postgres-new
  • Permanently deleted from the node corresponding to the volume, leaving only the volume corresponding to the primary node. If there is more dependent volumes (depending on the way you originally deployed Chart), delete all dependent volumes.
    kubectl delete pvc --namespace postgres-new SLAVE-PVC-NAME
  • Use Helm v3, create a new version of PostgreSQL in the new namespace. Chart of use persistence.existingClaim parameters. Alternatively and REPL-PASSWORD PASSWORD with previous versions of the database and user passwords and replaced with MASTER-PVC-NAME node name of the primary volume recovery.
    helm3 repo add bitnami https://charts.bitnami.com/bitnami
    helm3 install postgres bitnami/postgresql \   --set postgresqlPassword=PASSWORD \   --set replication.password=REPL-PASSWORD \   --set replication.slaveReplicas=1 \   --set replication.enabled=true \   --namespace postgres-new \   --set persistence.existingClaim=MASTER-PVC-NAME

    prompt

    Two versions of password keeping is very important to avoid authentication issues.

    This will create a new version using the previous version of the master volume (and therefore the data version before using). Note that, in the example above, if the copy is enabled, the installation will automatically create a new Chart of dependent volumes for each slave node.

  • Connected to the new version, and make sure your data is complete:
    kubectl run postgres-postgresql-client --rm --tty -i --restart='Never' --namespace postgres-new --image docker.io/bitnami/postgresql:11.7.0-debian-10-r9 --env="PGPASSWORD=$POSTGRES_PASSWORD" --command -- psql --host postgres-postgresql -U postgres -d postgres -p 5432

Step 4: Testing the upgrade process (optional)

You should now be able to upgrade to the new version. You can use the following command to test this, where VERSION is replaced with Chart version to be upgraded:

helm3 upgrade --version VERSION postgres bitnami/postgresql --set postgresqlPassword=hell0 --set replication.password=repl --set replication.slaveReplicas=1 --set replication.enabled=true --namespace postgres-new --set persistence.existingClaim=data-postgres-postgresql-master-0

prompt

When the upgrade version, use the same installation parameters.

After confirming that everything is normal, you can choose to delete the previous version.

Translation link:  https://docs.bitnami.com/tutorials/resolve-helm2-helm3-post-migration-issues/

Guess you like

Origin www.cnblogs.com/jinanxiaolaohu/p/12632453.html