How to access OCI Container Engine for Kubernetes(OKE) and Deploy sample Apllication
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:
- In the Console, open the navigation menu and click Developer Services. Under Containers, click Kubernetes Clusters (OKE).
OKE |
- Choose a Compartment you have permission to work in.
- 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.
- Click the Access Cluster button to display the Access Your Cluster dialog box.
OKE access cluster |
- Click Cloud Shell Access.
- Click Launch Cloud Shell to display the Cloud Shell window.
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 |
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
where:
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