Nota:

Eseguire la migrazione del cluster di servizi Azure Kubernetes o del cluster Amazon EKS in Container Engine for Kubernetes utilizzando Velero

Introduzione

Velero è uno strumento open source per eseguire backup e ripristino in tutta sicurezza, eseguire il recupero da errori irreversibili ed eseguire la migrazione delle risorse cluster Kubernetes e dei volumi persistenti. Poiché lo storage degli oggetti Oracle Cloud Infrastructure (OCI) è S3-Compatible, è possibile utilizzare il plugin AWS di Velero. In questo tutorial, useremo Azure Kubernetes Service (AKS), ma i passi dovrebbero anche funzionare perfettamente in Amazon Elastic Kubernetes Service (Amazon EKS).

Il diagramma riportato di seguito offre una panoramica del funzionamento del processo.

diagramma

Per questa esercitazione abbiamo preparato un pod NGINX a cui è allegata una richiesta di volume persistente e un file index.html personalizzato e un segreto fittizio.

  > 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

Obiettivi

Prerequisiti

Task 1: creare il file velero-credentials con la chiave segreta del cliente all'interno

  1. Se non si dispone già di una chiave segreta del cliente, è possibile seguire queste fasi.

  2. Sul computer utilizzato per accedere ai cluster AKS/EKS e OKE (o Cloud Shell) creare il file velero-credentials con il contenuto seguente:

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

Task 2: Scaricare e installare Velero

  1. Installare Velero sul computer che verrà utilizzato per accedere ai cluster, seguendo queste procedure o, se si utilizza Cloud Shell, scaricarlo qui.

  2. Procedere con l'installazione di Velero in entrambi i cluster AKS e OKE con il seguente comando.

    Nota: se i file binari sono stati scaricati, eseguire velero utilizzando ./ all'inizio:

    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. Verificare che Velero sia stato installato in AKS e OKE eseguendo il comando seguente.

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

Task 3: eseguire il backup del cluster

  1. Nel cluster AKS eseguire il comando seguente. In questa esercitazione, stiamo utilizzando l'interfaccia CLI di Azure con i file binari velero scaricati in essa.

    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. Verificare che sia stato eseguito il backup 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")
    

Task 4: Ripristino o migrazione in OKE

  1. AKS, EKS e OKE utilizzano un valore storageClassNames diverso per le richieste di volume persistenti. È necessario creare un valore configMap che traduca l'origine storageClassNames in un nome di classe compatibile con OCI. A tale scopo, viene creato il file configMap.yaml con il seguente contenuto. Adattalo alla tua fonte storageClassName.

    IMPORTANTE: è necessario completare il passo 1, altrimenti i pod rimarranno in stato in sospeso.

    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. Applicare il comando configMap al cluster OKE con il comando seguente.

    kubectl apply -f configMap.yaml

  3. Verificare che il cluster OKE possa accedere ai backup dallo storage degli oggetti.

    $ 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. Creare il ripristino con il comando seguente.

    $ 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. Verificare lo stato del ripristino.

    $ 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. Verificare che la migrazione del cluster sia stata completata.

    $ 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
    

Approvazioni

Altre risorse di apprendimento

Esplora altri laboratori su docs.oracle.com/learn o accedi a contenuti di formazione gratuiti sul canale YouTube di Oracle Learning. Inoltre, visitare education.oracle.com/learning-explorer per diventare Explorer di Oracle Learning.

Per la documentazione sul prodotto, visitare il sito Oracle Help Center.