Nota:

Migre el cluster de servicio de Azure Kubernetes o el cluster de Amazon EKS al motor de contenedor para Kubernetes mediante Velero

Introducción

Velero es una herramienta de código abierto para realizar copias de seguridad y restauraciones de forma segura, realizar recuperaciones ante desastres y migrar recursos de cluster de Kubernetes y volúmenes persistentes. Como Oracle Cloud Infrastructure (OCI) Object Storage es S3-Compatible, podemos utilizar el plugin AWS de Velero. En este tutorial, utilizaremos Azure Kubernetes Service (AKS), pero los pasos también deben funcionar sin problemas en Amazon Elastic Kubernetes Service (Amazon EKS).

En el siguiente diagrama se ofrece una descripción general del funcionamiento del proceso.

diagrama

Para este tutorial, hemos preparado un pod NGINX que tiene una reclamación de volumen persistente asociada y un archivo index.html personalizado en él, y un secreto ficticio.

  > kubectl get pods --n nginx      
  NAME          READY   STATUS    RESTARTS   AGE
  task-pv-pod   1/1     Running   0          47h
  > kubectl exec -it task-pv-pod --n nginx -- curl localhost
  AKS to OKE Migration with PVC attached
  >kubectl get secrets --namespace nginx
  NAME           TYPE     DATA   AGE
  okemigration   Opaque   1      2s

Objetivos

Requisitos

Tarea 1: Crear el archivo velero-credentials con la clave secreta de cliente dentro

  1. Si aún no tiene una clave secreta de cliente, puede seguir estos pasos.

  2. En la máquina que utiliza para acceder a los clusters AKS/EKS y OKE (o Cloud Shells), cree el archivo velero-credentials con el siguiente contenido:

      [default]
      aws_access_key_id=<<Access Key ID>>
      aws_secret_access_key=<<Generated Key>>
    
    

Tarea 2: Descarga e instalación de Velero

  1. Instale Velero en la máquina que utilizará para acceder a los clusters, siguiendo estos pasos o, si utiliza Cloud Shell, descárguelo desde aquí.

  2. Continúe con la instalación de Velero en los clusters AKS y OKE con el siguiente comando.

    Nota: Si ha descargado los binarios, ejecute velero con ./ al principio:

    velero install \
    --provider aws \
    --bucket <<Bucket name>> \
    --prefix <<Tenancy name>> \
    --use-volume-snapshots=false \
    --plugins velero/velero-plugin-for-aws:v1.6.0 \
    --secret-file <<Location of the file created with the customer secret key>> \
    --backup-location-config region=<<Region>>,s3ForcePathStyle="true",s3Url=https://<<tenancy name>>.compat.objectstorage.<<region>>.oraclecloud.com \
    --use-node-agent
    
  3. Verifique que Velero se haya instalado en AKS y OKE ejecutando el siguiente comando.

    > kubectl get deployment -n velero
    NAME     READY   UP-TO-DATE   AVAILABLE   AGE
    velero   1/1     1            1           47h
    

Tarea 3: Copia de seguridad del cluster

  1. En el cluster de AKS, ejecute el siguiente comando. En este tutorial, estamos utilizando Azure CLI con los binarios velero descargados en él.

    velero-v1.11.1-rc.1-linux-amd64> ./velero backup create nginxoke --include-namespaces nginx --default-volumes-to-fs-backup
    Backup request "nginxoke" submitted successfully.
    Run `velero backup describe nginxoke` or `velero backup logs nginxoke` for more details.
    
  2. Verifique que se realice una copia de seguridad del cluster.

       velero-v1.11.1-rc.1-linux-amd64> ./velero backup describe nginxoke
       Name:         nginxoke
       Namespace:    velero
       Labels:       velero.io/storage-location=default
       Annotations:  velero.io/source-cluster-k8s-gitversion=v1.24.10
                   velero.io/source-cluster-k8s-major-version=1
                   velero.io/source-cluster-k8s-minor-version=24
       Phase:  Completed
       Namespaces:
       Included:  nginx
       Excluded:  <none>
       .................
    You can also check the Object Storage Bucket:
    ![bucket](./images/bucket.png "Storage Bucket")
    

Tarea 4: Restauración o migración a OKE

  1. Como AKS, EKS y OKE utilizan diferentes storageClassNames para las reclamaciones de volumen persistentes, necesitamos crear un configMap que traduzca el origen storageClassNames a un nombre de clase compatible con OCI. Para ello, creamos el archivo configMap.yaml con el siguiente contenido. Adáptalo a tu código fuente storageClassName.

    IMPORTANTE: debe completar el paso 1; de lo contrario, los pods permanecerán en estado pendiente.

    apiVersion: v1
    kind: ConfigMap
    metadata:
    # any name can be used; Velero uses the labels (below)
    # to identify it rather than the name
    name: change-storage-class-config
    # must be in the velero namespace
    namespace: velero
    # the below labels should be used verbatim in your
    # ConfigMap.
    labels:
        # this value-less label identifies the ConfigMap as
        # config for a plugin (i.e. the built-in change storage
        # class restore item action plugin)
        velero.io/plugin-config: ""
        # this label identifies the name and kind of plugin
        # that this ConfigMap is for.
        velero.io/change-storage-class: RestoreItemAction
    data:
    # add 1+ key-value pairs here, where the key is the old
    # storage class name and the value is the new storage
    # class name.
    <old-storage-class>: oci-bv
    
  2. Aplique configMap al cluster de OKE con el siguiente comando.

    kubectl apply -f configMap.yaml

  3. Verifique que el cluster de OKE pueda acceder a las copias de seguridad desde el almacenamiento de objetos.

    $ velero get backup
    NAME         STATUS            ERRORS   WARNINGS   CREATED                          EXPIRES   STORAGE LOCATION   SELECTOR
    nginxoke     Completed         0        0          2023-07-22 14:40:33 +0300 EEST   29d       default            <none>
    
  4. Cree la restauración con el siguiente comando.

    $ velero restore create --from-backup nginxoke
    Restore request "nginxoke-20230722145553" submitted successfully.
    Run `velero restore describe nginxoke-20230722145553` or `velero restore logs nginxoke-20230722145553` for more details.
    
  5. Verifique el estado de restauración.

    $ velero restore describe nginxoke-20230722145553
    Name:         nginxoke-20230722145553
    Namespace:    velero
    Labels:       <none>
    Annotations:  <none>
    Phase:                       Completed
    Total items to be restored:  7
    Items restored:              7
    Started:    2023-07-22 14:55:54 +0300 EEST
    Completed:  2023-07-22 14:56:45 +0300 EEST
    ..........
    
  6. Verifique que el cluster se haya migrado correctamente.

    $ kubectl get pod -n nginx
    NAME          READY   STATUS    RESTARTS   AGE
    task-pv-pod   1/1     Running   0          2m15s
    $ kubectl get secrets -n nginx
    NAME           TYPE     DATA   AGE
    okemigration   Opaque   1      2m21s
    $ kubectl get pvc -n nginx
    NAME            STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
    task-pv-claim   Bound    csi-d03267f7-32cf-4068-8809-d29aa649dcba   50Gi       RWO            oci-bv         2m31s
    $ kubectl exec task-pv-pod -n nginx -- curl http://localhost
    AKS to OKE Migration with PVC attached
    

Acuses de recibo

Más recursos de aprendizaje

Explore otros laboratorios en docs.oracle.com/learn o acceda a más contenido de aprendizaje gratuito en el canal YouTube de Oracle Learning. Además, visite education.oracle.com/learning-explorer para convertirse en un explorador de Oracle Learning.

Para obtener documentación sobre los productos, visite Oracle Help Center.