Note:

Build Oracle Cloud Native Environment from Source

Introduction

The Oracle Cloud Native Environment (Oracle CNE) Command Line Interface (CLI) manages the lifecycle of the Kubernetes cluster at your organization. It is also an Open Source project available on GitHub, and this tutorial demonstrates how to build the ocne executable yourself.

For more information about Oracle Cloud Native Environment 2, please refer to the current Release Documentation site.

Objectives

In this tutorial, you’ll learn to:

Prerequisites

Configure the Oracle Cloud Native Environment

Note: If running in your own tenancy, read the linux-virt-labs GitHub project README.md and complete the prerequisites before deploying the lab environment.

  1. Open a terminal on the Luna Desktop.

  2. Clone the linux-virt-labs GitHub project.

    git clone https://github.com/oracle-devrel/linux-virt-labs.git
    
  3. Change into the working directory.

    cd linux-virt-labs/ocne2
    
  4. Install the required collections.

    ansible-galaxy collection install -r requirements.yml
    
  5. Deploy the lab environment.

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

    The free lab environment requires the extra variable local_python_interpreter, which sets ansible_python_interpreter for plays running on localhost. This variable is needed because the environment installs the RPM package for the Oracle Cloud Infrastructure SDK for Python, located under the python3.6 modules.

    The default deployment shape uses the AMD CPU and Oracle Linux 8. To use an Intel CPU or Oracle Linux 9, add -e instance_shape="VM.Standard3.Flex" or -e os_version="9" to the deployment command.

    Important: Wait for the playbook to run successfully and reach the pause task. At this stage of the playbook, the installation of the Oracle Cloud Native Environment is complete, and the instances are ready. Take note of the previous play, which prints the public and private IP addresses of the nodes it deploys and any other deployment information needed while running the lab.

Install the Prerequisites

  1. Open a terminal and connect via SSH to the ocne instance.

    ssh oracle@<ip_address_of_instance>
    
  2. Install Git.

    sudo dnf install git -y
    
  3. Clone the Oracle CNE repo.

    git clone https://github.com/oracle-cne/ocne.git
    
  4. Change into the working directory.

    cd ocne
    
  5. List the available Oracle Cloud Native Environment packages.

    sudo dnf search ocne
    

    Example Output:

    [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. Install the repository package.

    Oracle Linux 8

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

    Oracle Linux 9

    sudo dnf install -y oracle-ocne-release-el9
    
  7. Enable the 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. Enable the Codeready repository.

    The CodeReady repository provides many packages and tools for developers to build and package applications.

    Oracle Linux 8

    sudo dnf config-manager --enable ol8_codeready_builder
    

    Oracle Linux 9

    sudo dnf config-manager --enable ol9_codeready_builder
    
  9. Confirm the repositories are enabled.

    sudo dnf repolist
    
  10. Update the Helm requirement for Oracle Linux 9.

    Oracle Linux 8

    Not required.

    Oracle Linux 9

    sed -i 's/3.13.0/3.12.0/' buildrpm/ocne.spec
    
  11. Install the prerequisites.

    sudo yum-builddep buildrpm/ocne.spec -y
    

    Example Output:

    [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   
    

Build the Executable

  1. Check the available options.

    make
    

    Example Output:

    [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. Build the executable.

    make build-cli
    

    Example Output:

    [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. Confirm the executable is present.

    ls -al out/linux_amd64/
    

    Example Output:

    [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. Confirm it works.

    out/linux_amd64/ocne info
    

    Example Output:

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

    Note the Version and BuildDate values. The Version reflects the latest version in Main, and the BuildDate reflects the Date and Time you built the ocne executable.

Create a Single Node Cluster

  1. Create a single node Oracle Cloud Native Environment cluster.

    out/linux_amd64/ocne cluster start
    

    Depending on your machine’s available resources, the cluster creation can take several minutes to complete while it downloads the image source and sets it up.

    Once completed, enter y to complete the installation and return to the command prompt. Ignore the rest of the post-install steps and proceed to the next step.

    Example Output:

    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. Install the Kubernetes command line tool (kubectl)

    sudo dnf install -y kubectl
    
  3. Configure kubectl to use the newly created cluster.

    export KUBECONFIG=$HOME/.kube/kubeconfig.ocne.local
    
  4. Confirm that the cluster consists of only one node.

    kubectl get nodes --all-namespaces
    

    Example Output:

    [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. Confirm the successful deployment of the cluster.

    kubectl get deployments --all-namespaces
    

    Example Output:

    [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. List all of the pods deployed.

    kubectl get pods --all-namespaces
    

    Example Output:

    [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
    

    This output confirms you have successfully built ocne from the source code and created a new Kubernetes cluster.

Next steps

This tutorial demonstrated how to build the Oracle CNE CLI from the source code on GitHub, which is helpful for local testing. However, this is only the start. Check out the Oracle Linux Training Station for additional tutorials and content.

More Learning Resources

Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.

For product documentation, visit Oracle Help Center.