Nota

Crea Oracle Cloud Native Environment dall'origine

Introduzione

L'interfaccia CLI (Command Line Interface) Oracle Cloud Native Environment (Oracle CNE) gestisce il ciclo di vita del cluster Kubernetes nella tua organizzazione. Si tratta inoltre di un progetto Open Source disponibile su GitHub e questa esercitazione descrive come creare autonomamente l'eseguibile ocne.

Per ulteriori informazioni su Oracle Cloud Native Environment 2, fai riferimento al sito corrente della documentazione sulla release.

Obiettivi

In questo tutorial imparerai a:

Prerequisiti

Configurare Oracle Cloud Native Environment

Nota: se è in esecuzione nella propria tenancy, leggere il progetto linux-virt-labs GitHub README.md e completare i prerequisiti prima di distribuire l'ambiente di esercitazione pratica.

  1. Aprire un terminale sul Luna Desktop.

  2. Duplica il progetto linux-virt-labs GitHub.

    git clone https://github.com/oracle-devrel/linux-virt-labs.git
    
  3. Passare alla directory di lavoro.

    cd linux-virt-labs/ocne2
    
  4. Installare le raccolte richieste.

    ansible-galaxy collection install -r requirements.yml
    
  5. Implementa l'ambiente di laboratorio.

    ansible-playbook create_instance.yml -e localhost_python_interpreter="/usr/bin/python3.6" -e ocne_type=libvirt
    

    L'ambiente di laboratorio gratuito richiede la variabile aggiuntiva local_python_interpreter, che imposta ansible_python_interpreter per le riproduzioni in esecuzione su localhost. Questa variabile è necessaria perché l'ambiente installa il pacchetto RPM per l'SDK Oracle Cloud Infrastructure per Python, situato sotto i moduli python3.6.

    La forma di distribuzione predefinita utilizza la CPU AMD e Oracle Linux 8. Per utilizzare una CPU Intel o Oracle Linux 9, aggiungere -e instance_shape="VM.Standard3.Flex" o -e os_version="9" al comando di distribuzione.

    Importante: attendere la corretta esecuzione della guida e raggiungere il task di sospensione. In questa fase della guida, l'installazione di Oracle Cloud Native Environment è stata completata e le istanze sono pronte. Prendi nota della riproduzione precedente, che stampa gli indirizzi IP pubblici e privati dei nodi che distribuisce e qualsiasi altra informazione di distribuzione necessaria durante l'esecuzione del laboratorio.

Installare i prerequisiti

  1. Aprire un terminale e connettersi tramite SSH all'istanza ocne.

    ssh oracle@<ip_address_of_instance>
    
  2. Installare Git.

    sudo dnf install git -y
    
  3. Duplica il repository Oracle CNE.

    git clone https://github.com/oracle-cne/ocne.git
    
  4. Passare alla directory di lavoro.

    cd ocne
    
  5. Elenca i pacchetti Oracle Cloud Native Environment disponibili.

    sudo dnf search ocne
    

    Output di esempio:

    [oracle@ocne ~]$ sudo dnf search ocne
    Last metadata expiration check: 0:01:00 ago on Fri 28 Mar 2025 11:48:50 AM GMT.
    ========================================================== Name Matched: ocne ===========================================================
    oracle-ocne-release-el8.src : Oracle Cloud Native Environment yum repository configuration
    oracle-ocne-release-el8.x86_64 : Oracle Cloud Native Environment yum repository configuration
    
  6. Installare il pacchetto del repository.

    Oracle Linux 8

    sudo dnf install -y oracle-ocne-release-el8
    

    Oracle Linux 9

    sudo dnf install -y oracle-ocne-release-el9
    
  7. Abilitare il repository.

    Oracle Linux 8

    sudo dnf config-manager --enable ol8_ocne
    

    Oracle Linux 9

    sudo dnf config-manager --enable ol9_ocne
    sudo dnf config-manager --enable ol9_olcne19
    
  8. Abilitare il repository Codeready.

    Il repository CodeReady fornisce molti pacchetti e strumenti che gli sviluppatori possono utilizzare per creare e creare pacchetti di applicazioni.

    Oracle Linux 8

    sudo dnf config-manager --enable ol8_codeready_builder
    

    Oracle Linux 9

    sudo dnf config-manager --enable ol9_codeready_builder
    
  9. Verificare che i repository siano abilitati.

    sudo dnf repolist
    
  10. Aggiorna il requisito Helm per Oracle Linux 9.

    Oracle Linux 8

    Facoltativa.

    Oracle Linux 9

    sed -i 's/3.13.0/3.12.0/' buildrpm/ocne.spec
    
  11. Installare i prerequisiti.

    sudo yum-builddep buildrpm/ocne.spec -y
    

    Output di esempio:

    [oracle@ocne ocne]$ sudo yum-builddep buildrpm/ocne.spec 
    Oracle Linux 8 BaseOS Latest (x86_64)                                                                    317 kB/s | 4.3 kB     00:00    
    Oracle Linux 8 Application Stream (x86_64)                                                                69 kB/s | 4.5 kB     00:00    
    Oracle Linux 8 CodeReady Builder (x86_64) - Unsupported                                                   39 MB/s |  12 MB     00:00    
    Oracle Linux 8 Addons (x86_64)                                                                           184 kB/s | 3.5 kB     00:00    
    Oracle Cloud Native Environment version 2.0 (x86_64)                                                      30 MB/s | 6.1 MB     00:00    
    Dependencies resolved.
    =========================================================================================================================================
     Package                           Architecture    Version                                          Repository                      Size
    =========================================================================================================================================
    Installing:
     btrfs-progs-devel                 x86_64          5.15.1-2.el8                                     ol8_UEKR7                       49 k
     device-mapper-devel               x86_64          8:1.02.181-15.0.1.el8_10                         ol8_codeready_builder          284 k
     golang                            x86_64          1.22.9-1.module+el8.10.0+90476+bb48cc15          ol8_appstream                  759 k
     gpgme-devel                       x86_64          1.13.1-12.el8                                    ol8_codeready_builder          166 k
     helm                              x86_64          3.17.1-2.el8                                     ol8_ocne                        12 M
     libassuan-devel                   x86_64          2.5.1-3.el8                                      ol8_codeready_builder           69 k
     rpm-build                         x86_64          4.14.3-32.0.1.el8_10                             ol8_appstream                  174 k
     yq                                x86_64          4.45.1-1.el8                                     ol8_ocne                       3.4 M
    Upgrading:
     btrfs-progs                       x86_64          5.15.1-2.el8                                     ol8_UEKR7                      864 k
    ...
    ...
      python3-rpm-macros-3-45.el8.noarch                                  qt5-srpm-macros-5.15.3-1.el8.noarch                                
      redhat-rpm-config-131-1.0.1.el8.noarch                              rpm-build-4.14.3-32.0.1.el8_10.x86_64                              
      rust-srpm-macros-5-2.el8.noarch                                     systemd-devel-239-82.0.3.el8_10.3.x86_64                           
      yq-4.45.1-1.el8.x86_64                                              zstd-1.4.4-1.0.1.el8.x86_64   
    

Crea l'eseguibile

  1. Controllare le opzioni disponibili.

    make
    

    Output di esempio:

    [oracle@ocne ocne]$ make
    
    Usage:
      make <target>
      help                       Display this help.
      build-cli                  Build CLI for the current system and architecture
      cli                        Build and install the CLI
      clean                      Delete output from prior builds
    
    Linting and coverage
      check                      Run all linters
      check-golangci-lint        Run Go linters
      install-golangci-lint      Install golangci-lint
      word-linter                Check for use of 'bad' words
    
  2. Creare l'eseguibile.

    make build-cli
    

    Output di esempio:

    [oracle@ocne ocne]$ make cli
    ...
    ...
    cd repo && helm repo index .
    make[1]: Leaving directory '/home/oracle/ocne/build/catalog'
    mkdir -p pkg/catalog/embedded/charts
    cp build/catalog/repo/* pkg/catalog/embedded/charts
    mkdir -p out/linux_amd64
    GOTOOLCHAIN=local GO111MODULE=on GOPRIVATE=github.com/oracle-cne/ocne go build -trimpath -ldflags "-X 'github.com/oracle-cne/ocne/cmd/info.gitCommit=1101a5b5fb72e9812aa14cf68613d28440f1bc57' -X 'github.com/oracle-cne/ocne/cmd/info.buildDate=2025-04-02T09:54:53Z' -X 'github.com/oracle-cne/ocne/cmd/info.cliVersion=2.1.2-3.el8'" -tags developer -o out/linux_amd64 ./...
    
  3. Confermare la presenza dell'eseguibile.

    ls -al out/linux_amd64/
    

    Output di esempio:

    [oracle@ocne ocne]$ ls -al out/linux_amd64/
    total 194744
    drwxrwxr-x. 2 oracle oracle        18 Mar 28 12:35 .
    drwxrwxr-x. 3 oracle oracle        25 Mar 28 12:30 ..
    -rwxrwxr-x. 1 oracle oracle 199415168 Mar 28 12:35 ocne
    
  4. Confermare che funziona.

    out/linux_amd64/ocne info
    

    Output di esempio:

    [oracle@ocne ocne]$ out/linux_amd64/ocne info
    CLI Info
    Name     	Value                                   
    Version  	2.1.2-3.el8                             
    BuildDate	2025-04-02T09:54:53Z                    
    GitCommit	1101a5b5fb72e9812aa14cf68613d28440f1bc57
    
    Environment Variables
    Name         	Description                                       	Current Value
    OCNE_DEFAULTS	Sets the location of the default configuration    	             
                 	file.                                             	             
    KUBECONFIG   	Sets the location of the kubeconfig file. This    	             
                 	behaves the same way as the --kubeconfig option   	             
                 	for most ocne commands.                           	             
    EDITOR       	Sets the default document editor.
    

    Prendere nota dei valori Versione e BuildDate. La Versione riflette la versione più recente in Principale e BuildDate riflette la data e l'ora in cui è stato creato l'eseguibile ocne.

Creare un cluster a nodo singolo

  1. Creare un cluster Oracle Cloud Native Environment a nodo singolo.

    out/linux_amd64/ocne cluster start
    

    A seconda delle risorse disponibili del computer, il completamento della creazione del cluster può richiedere alcuni minuti mentre scarica l'origine dell'immagine e la imposta.

    Al termine, immettere y per completare l'installazione e tornare al prompt dei comandi. Ignorare il resto dei passi successivi all'installazione e passare al passo successivo.

    Output di esempio:

    Run the following command to create an authentication token to access the UI:
        KUBECONFIG='/home/oracle/.kube/kubeconfig.ocne.local' kubectl create token ui -n ocne-system
    Browser window opened, enter 'y' when ready to exit: y
    
    INFO[2025-03-28T13:10:04Z] Post install information:
    
    To access the cluster from the VM host:
        copy /home/oracle/.kube/kubeconfig.ocne.vm to that host and run kubectl there
    To access the cluster from this system:
        use /home/oracle/.kube/kubeconfig.ocne.local
    To access the UI, first do kubectl port-forward to allow the browser to access the UI.
    Run the following command, then access the UI from the browser using via https://localhost:8443
        kubectl port-forward -n ocne-system service/ui 8443:443
    Run the following command to create an authentication token to access the UI:
        kubectl create token ui -n ocne-system
    
  2. Installare lo strumento della riga di comando Kubernetes (kubectl)

    sudo dnf install -y kubectl
    
  3. Configurare kubectl per utilizzare il cluster appena creato.

    export KUBECONFIG=$HOME/.kube/kubeconfig.ocne.local
    
  4. Verificare che il cluster sia costituito da un solo nodo.

    kubectl get nodes --all-namespaces
    

    Output di esempio:

    [oracle@ocne ~]$ kubectl get nodes --all-namespaces
    NAME                   STATUS   ROLES           AGE     VERSION
    ocne-control-plane-1   Ready    control-plane   2m23s   v1.31.6+1.el8
    
  5. Confermare la distribuzione riuscita del cluster.

    kubectl get deployments --all-namespaces
    

    Output di esempio:

    [oracle@ocne ~]$ kubectl get deployments --all-namespaces
    NAMESPACE     NAME           READY   UP-TO-DATE   AVAILABLE   AGE
    kube-system   coredns        2/2     2            2           15m
    ocne-system   ocne-catalog   1/1     1            1           15m
    ocne-system   ui             1/1     1            1           15m
    
  6. Elenca tutti i pod distribuiti.

    kubectl get pods --all-namespaces
    

    Output di esempio:

    [oracle@ocne ~]$ kubectl get pods --all-namespaces
    NAMESPACE      NAME                                           READY   STATUS    RESTARTS      AGE
    kube-flannel   kube-flannel-ds-8fbm2                          1/1     Running   0.            13m
    kube-system    coredns-f7d444b54-njk46                        1/1     Running   0             13m
    kube-system    coredns-f7d444b54-xn975                        1/1     Running   0             13m
    kube-system    etcd-ocne-control-plane-1                      1/1     Running   0             13m
    kube-system    kube-apiserver-ocne-control-plane-1            1/1     Running   0             13m
    kube-system    kube-controller-manager-ocne-control-plane-1   1/1     Running   0             13m
    kube-system    kube-proxy-jsfqs                               1/1     Running   0             13m
    kube-system    kube-scheduler-ocne-control-plane-1            1/1     Running   0             13m
    ocne-system    ocne-catalog-578c959566-75rr5                  1/1     Running   0             13m
    ocne-system    ui-84dd57ff69-grxlk                            1/1     Running   0             13m
    

    Questo output conferma che la creazione di ocne dal codice sorgente è riuscita e che è stato creato un nuovo cluster Kubernetes.

Passi successivi

Questa esercitazione ha illustrato come creare l'interfaccia CLI Oracle CNE dal codice sorgente su GitHub, utile per i test locali. Tuttavia, questo è solo l'inizio. Dai un'occhiata alla Training Station di Oracle Linux per tutorial e contenuti aggiuntivi.

Altre risorse di apprendimento

Esplora altri laboratori su docs.oracle.com/learn o accedi a più contenuti gratuiti sulla formazione su Oracle Learning YouTube channel. Inoltre, visita education.oracle.com/learning-explorer per diventare un Oracle Learning Explorer.

Per la documentazione del prodotto, visita l'Oracle Help Center.