ノート:

ソースからのOracle Cloud Native Environmentの構築

イントロダクション

Oracle Cloud Native Environment (Oracle CNE)コマンドライン・インタフェース(CLI)は、組織のKubernetesクラスタのライフサイクルを管理します。また、GitHubで使用可能なオープン・ソース・プロジェクトでもあり、このチュートリアルでは、ocne実行可能ファイルを自分で構築する方法を示します。

Oracle Cloud Native Environment 2の詳細は、現在のリリース・ドキュメンテーション・サイトを参照してください。

目的

このチュートリアルでは、次のことを学習します。

前提条件

Oracle Cloud Native Environmentの構成

ノート:独自のテナンシで実行している場合は、linux-virt-labs GitHubプロジェクトREADME.mdを読み、演習環境をデプロイする前に前提条件を完了してください。

  1. Lunaデスクトップでターミナルを開きます。

  2. linux-virt-labs GitHubプロジェクトをクローニングします。

    git clone https://github.com/oracle-devrel/linux-virt-labs.git
    
  3. 作業ディレクトリに移動します。

    cd linux-virt-labs/ocne2
    
  4. 必要なコレクションをインストールします。

    ansible-galaxy collection install -r requirements.yml
    
  5. 演習環境をデプロイします。

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

    無料の演習環境では、追加変数local_python_interpreterが必要です。この変数は、localhostで実行されている再生用にansible_python_interpreterを設定します。この変数は、python3.6モジュールの下にあるOracle Cloud Infrastructure SDK for PythonのRPMパッケージが環境によってインストールされるため必要です。

    デフォルトのデプロイメント・シェイプでは、AMD CPUおよびOracle Linux 8が使用されます。Intel CPUまたはOracle Linux 9を使用するには、デプロイメント・コマンドに-e instance_shape="VM.Standard3.Flex"または-e os_version="9"を追加します。

    重要:プレイブックが正常に実行されるまで待機し、一時停止タスクに到達します。プレイブックのこの段階で、Oracle Cloud Native Environmentのインストールが完了し、インスタンスの準備ができました。前の再生に注意してください。これは、デプロイするノードのパブリックIPアドレスとプライベートIPアドレス、および演習の実行中に必要なその他のデプロイメント情報を出力します。

前提条件のインストール

  1. 端末を開き、SSHを介してocneインスタンスに接続します。

    ssh oracle@<ip_address_of_instance>
    
  2. Gitのインストール

    sudo dnf install git -y
    
  3. Oracle CNEリポジトリをクローニングします。

    git clone https://github.com/oracle-cne/ocne.git
    
  4. 作業ディレクトリに移動します。

    cd ocne
    
  5. 使用可能なOracle Cloud Native Environmentパッケージをリストします。

    sudo dnf search ocne
    

    出力例:

    [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. リポジトリパッケージをインストールします。

    Oracle Linux 8

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

    Oracle Linux 9

    sudo dnf install -y oracle-ocne-release-el9
    
  7. リポジトリを有効にします。

    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. Codereadyリポジトリを有効にします。

    CodeReadyリポジトリは、開発者がアプリケーションをビルドおよびパッケージ化するための多くのパッケージおよびツールを提供します。

    Oracle Linux 8

    sudo dnf config-manager --enable ol8_codeready_builder
    

    Oracle Linux 9

    sudo dnf config-manager --enable ol9_codeready_builder
    
  9. リポジトリが有効になっていることを確認します。

    sudo dnf repolist
    
  10. Oracle Linux 9のHelm要件を更新します。

    Oracle Linux 8

    必須ではありません。

    Oracle Linux 9

    sed -i 's/3.13.0/3.12.0/' buildrpm/ocne.spec
    
  11. 前提条件をインストールします。

    sudo yum-builddep buildrpm/ocne.spec -y
    

    出力例:

    [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   
    

実行可能ファイルのビルド

  1. 使用可能なオプションを確認します。

    make
    

    出力例:

    [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. 実行可能ファイルをビルドします。

    make build-cli
    

    出力例:

    [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. 実行可能ファイルが存在することを確認します。

    ls -al out/linux_amd64/
    

    出力例:

    [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. 動作していることを確認します。

    out/linux_amd64/ocne info
    

    出力例:

    [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.
    

    Versionおよび BuildDate値を書き留めます。「バージョン」には「メイン」の最新バージョンが反映され、BuildDateにはocne実行可能ファイルをビルドした日時が反映されます。

単一ノードクラスタの作成

  1. 単一ノードのOracle Cloud Native Environmentクラスタを作成します。

    out/linux_amd64/ocne cluster start
    

    マシンで使用可能なリソースによっては、イメージ・ソースをダウンロードして設定している間、クラスタの作成が完了するまでに数分かかる場合があります。

    完了したら、yと入力してインストールを完了し、コマンド・プロンプトに戻ります。インストール後の残りのステップは無視して、次のステップに進みます。

    出力例:

    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. Kubernetesコマンドライン・ツールのインストール (kubectl)

    sudo dnf install -y kubectl
    
  3. 新しく作成したクラスタを使用するようにkubectlを構成します。

    export KUBECONFIG=$HOME/.kube/kubeconfig.ocne.local
    
  4. クラスタが1つのノードのみで構成されていることを確認します。

    kubectl get nodes --all-namespaces
    

    出力例:

    [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. クラスタの正常なデプロイメントを確認します。

    kubectl get deployments --all-namespaces
    

    出力例:

    [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. デプロイされたすべてのポッドをリストします。

    kubectl get pods --all-namespaces
    

    出力例:

    [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
    

    この出力により、ソース・コードからocneを正常に構築し、新しいKubernetesクラスタを作成したことが確認されます。

次のステップ

このチュートリアルでは、ローカル・テストに役立つGitHubのソース・コードからOracle CNE CLIを構築する方法を示します。しかし、これは始まりに過ぎません。その他のチュートリアルおよびコンテンツについては、Oracle Linuxトレーニング・ステーションを参照してください。

その他の学習リソース

docs.oracle.com/learnの他のラボを確認するか、Oracle Learning YouTubeチャネルで無料のラーニング・コンテンツにアクセスしてください。また、education.oracle.com/learning-explorerにアクセスしてOracle Learning Explorerになります。

製品ドキュメントについては、Oracle Help Centerを参照してください。