Nota:
- Questa esercitazione richiede l'accesso a Oracle Cloud. Per iscriversi a un account gratuito, consulta Inizia a utilizzare Oracle Cloud Infrastructure Free Tier.
- Utilizza valori di esempio per le credenziali, la tenancy e i compartimenti di Oracle Cloud Infrastructure. Al termine del laboratorio, sostituisci questi valori con quelli specifici del tuo ambiente cloud.
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.

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
- Crea chiavi segrete del cliente da usare con l'endpoint S3 del bucket di storage degli oggetti.
- Imposta Velero in AKS e Oracle Cloud Infrastructure Container Engine for Kubernetes (OKE).
- Eseguire un backup e un ripristino per eseguire la migrazione di uno spazio di nomi Kubernetes in OKE.
Prerequisiti
- Conoscenza intermedia su Kubernetes.
- Un bucket di storage degli oggetti che verrà utilizzato come punto di backup.
- Privilegi utente di lettura/scrittura nel bucket di storage degli oggetti.
- File binari Velero nel computer utilizzato per connettersi al cluster Kubernetes o all'interno delle Cloud Shell sia di Microsoft Azure che di OCI.
Task 1: creare il file velero-credentials con la chiave segreta del cliente all'interno
-
Se non si dispone già di una chiave segreta del cliente, è possibile seguire queste fasi.
-
Sul computer utilizzato per accedere ai cluster AKS/EKS e OKE (o Cloud Shell) creare il file
velero-credentialscon il contenuto seguente:[default] aws_access_key_id=<<Access Key ID>> aws_secret_access_key=<<Generated Key>>
Task 2: Scaricare e installare Velero
-
Installare Velero sul computer che verrà utilizzato per accedere ai cluster, seguendo queste procedure o, se si utilizza Cloud Shell, scaricarlo qui.
-
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 -
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
-
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. -
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: 
Task 4: Ripristino o migrazione in OKE
-
AKS, EKS e OKE utilizzano un valore
storageClassNamesdiverso per le richieste di volume persistenti. È necessario creare un valore configMap che traduca l'originestorageClassNamesin un nome di classe compatibile con OCI. A tale scopo, viene creato il fileconfigMap.yamlcon il seguente contenuto. Adattalo alla tua fontestorageClassName.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 -
Applicare il comando configMap al cluster OKE con il comando seguente.
kubectl apply -f configMap.yaml -
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> -
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. -
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 .......... -
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
Collegamenti correlati
Approvazioni
- Guido Alejandro Ferreyra (Principal Cloud Architect)
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.
Migrate your Azure Kubernetes Service Cluster or Amazon EKS Cluster to Container Engine for Kubernetes using Velero
F84712-01
August 2023
Copyright © 2023, Oracle and/or its affiliates.