• Recent blogs

    How to access OCI Container Engine for Kubernetes(OKE) and Deploy sample Apllication

    How to access OCI Container Engine for Kubernetes(OKE) and Deploy  sample Apllication

    To access a cluster using kubectl, you have to set up a Kubernetes configuration file (commonly known as a 'kubeconfig' file) for the cluster. The kubeconfig file (by default named config and stored in the $HOME/.kube directory) provides the necessary details to access the cluster. Having set up the kubeconfig file, you can start using kubectl to manage the cluster. 

    In this blog we'll access the cluster using kubectl in Cloud Shell. 

    Setting Up Cloud Shell Access to Clusters

    When a cluster's Kubernetes API endpoint has a public IP address, you can access the cluster in Cloud Shell by setting up a kubeconfig file. When a cluster's Kubernetes API endpoint does not have a public IP address, you can access the cluster from a local workstation if your network is peered with the cluster's VCN. If there is a bastion host on a public subnet of the cluster's VCN, you can optionally complete an additional step to set up an SSH tunnel to the Kubernetes API endpoint.

    To set up the kubeconfig file:

    1. In the Consoleopen the navigation menu and click Developer Services. Under Containers, click Kubernetes Clusters (OKE).

    1. Choose a Compartment you have permission to work in.
    2. On the Cluster List page, click the name of the cluster you want to access using kubectl. The Cluster page shows details of the cluster.
    3. Click the Access Cluster button to display the Access Your Cluster dialog box.
    OKE access cluster
    OKE access cluster

    1. Click Cloud Shell Access.
    2. Click Launch Cloud Shell to display the Cloud Shell window. 
    3. Run the Oracle Cloud Infrastructure CLI command to set up the kubeconfig file and save it in a location accessible to kubectl.

      For example, enter the following command (or copy and paste it from the Access Your Cluster dialog box) in the Cloud Shell window:

    OKE cloud shell access
    OKE cloud shell access

    oci ce cluster create-kubeconfig --cluster-id ocid1.cluster.oc1.phx.aaaaaaaaae... --file $HOME/.kube/config  --region us-phoenix-1 --token-version 2.0.0 --kube-endpoint PUBLIC_ENDPOINT


    • ocid1.cluster.oc1.phx.aaaaaaaaae... is the OCID of the current cluster. For convenience, the command in the Access Your Cluster dialog box already includes the cluster's OCID.
    • --kube-endpoint PUBLIC_ENDPOINT specifies to add the public IP address of the cluster's Kubernetes API endpoint to the kubeconfig file.

    Note that if a kubeconfig file already exists in the location you specify, details about the cluster will be added as a new context to the existing kubeconfig file. The current-context: element in the kubeconfig file will be set to point to the newly-added context.

    Verify that kubectl can connect to the cluster by entering the following command in the Cloud Shell window:

    $ kubectl get nodes

    Information about the nodes in the cluster is shown.


    You can now use kubectl to perform operations on the cluster.

    Deploy a sample Application

    Deploy a sample hello world application by running the following command in your terminal.

    $ kubectl create -f https://k8s.io/examples/application/deployment.yaml

    No comments