Break New Ground

Deploy containers on Oracle Container Engine for Kubernetes using Developer Cloud

Abhinav Shroff
Principal Product Manager

In my previous blog, I described how to use Oracle Developer Cloud to build and push the Node.js microservice Docker image on DockerHub. This blog will help you understand, how to use Oracle Developer Cloud to deploy the Docker image pushed to DockerHub on Container Engine for Kubernetes.

Container Engine for Kubernetes

Container Engine for Kubernetes is a developer-friendly, container-native, enterprise-ready managed Kubernetes service for running highly available clusters with the control, security, and predictable performance of Oracle Cloud Infrastructure. Visit the following link to learn about Oracle’s Container Engine for Kubernetes:


Prerequisites for Kubernetes Deployment

  1. Access to an Oracle Cloud Infrastructure (OCI) account
  2. A Kubernetes cluster set up on OCI
    This tutorial explains how to set up a Kubernetes cluster on OCI. 

Set Up the Environment:

Create and Configure Build VM Templates and Build VMs

You’ll need to create and configure the Build VM template and Build VM with the required software, which will be used to execute the build job.


Click the user avatar, then select Organization from the menu. 


Click VM Templates then New Template. In the dialog that pops up, enter a template name, such as Kubernetes Template, select “Oracle Linux 7” for the platform, then click the Create button.  


After the template has been created, click Configure Software.


Select Kubectl and OCIcli (you’ll be asked to add Python3 3.6, as well) from the list of software bundles available for configuration, then click + to add these software bundles to the template. 

Click the Done button to complete the software configuration for that Build VM template.


From the Virtual Machines page, click +New VM and, in the dialog that pops up, enter the number of VMs you want to create and select the VM Template you just created (Kubernetes Template).


Click the Add button to add the VM.


Kubernetes deployment scripts

From the Project page, click the + New Repository button to add a new repository.


After creating the repository, Developer Cloud will bring you to the Code page, with the  NodejsKubernetes repository showing. Click the +File button to create a new file in the repository. (The README file in the repository was created when the project was created.) 


Copy the following script into a text editor and save the file as nodejs_micro.yaml.

apiVersion: apps/v1beta1
kind: Deployment
  name: nodejsmicro-k8s-deployment
      app: nodejsmicro
  replicas: 1 # deployment runs 1 pods matching the template
  template: # create pods using pod definition in this template
        app: nodejsmicro
      - name: nodejsmicro
        image: abhinavshroff/nodejsmicro4kube:latest
        - containerPort: 80 #Endpoint is at port 80 in the container
apiVersion: v1
kind: Service
  name: nodejsmicro-k8s-service
  type: NodePort #Exposes the service as a node port
  - port: 80
    protocol: TCP
    targetPort: 80
    app: nodejsmicro


Click the Commit button to create the file and commit the code changes.


Click the Commit button in the Commit changes dialog that displays.

You should see the nodejs_micro.yaml file in the list of files for the NodejsKubernetes.git repository, as shown in the screenshot below.


Configuring the Build Job

Click Build on the navigation bar to display the Build page. Click the +New Job button to create a new build job. In the New Job dialog box, enter NodejsKubernetesDeploymentBuild for the Job name and, from the Software Template drop-down list, select Kubernetes Template as the Software Template. Then click the Create Job button to create the build job.


After the build job has been created, you’ll be brought to the configure screen. Click the Source Control tab and select NodejsKubernetes.git from the repository drop-down list. This is the same repository where you created the nodejs_micro.yaml file. Select master from the Branch drop-down list.


In the Builders tab, click the Add Builder drop-down and select OCIcli Builder from the drop-down list. 

To see what you need to fill in for each of the input fields in the OCIcli Builder form and to find out where to retrieve these values, you can either read my “Oracle Cloud Infrastructure CLI on Developer Cloud” blog or the documentation link to the “Access Oracle Cloud Infrastructure Services Using OCIcli” section in Using Oracle Developer Cloud Service.

Note: The values in the screenshot below have been obfuscated for security reasons. 


Click the Add Builder drop-down list again and select Unix Shell Builder.


In the text area of the Unix Shell Builder, add the following script that downloads the Kubernetes config file and deploys the container on Oracle Kubernetes Engine, which you created by following the instructions in my previous blog. Click the Save button to save the build job. 


mkdir -p $HOME/.kube
oci ce cluster create-kubeconfig --cluster-id ocid1.cluster.oc1.iad.aaaaaaaaafrgkzrwhtimldhaytgnjqhazdgmbuhc2gemrvmq2w --file $HOME/.kube/config --region us-ashburn-1
export KUBECONFIG=$HOME/.kube/config
kubectl config view
kubectl get nodes
kubectl create -f nodejs_micro.yaml
sleep 120
kubectl get services nodejsmicro-k8s-service
kubectl get pods
kubectl describe pods

This script creates the kube directory, uses the OCIcli command oci ce cluster to download the Kubernetes cluster config file, then sets the KUBECONFIG environment variable.

The kubectl config and get nodes commands just let you view the cluster configuration and see the node details of the cluster. The create command actually deploys the Docker container on the Kubernetes cluster. We run the get services and, get pods commands to retrieve the IP address and the port of the deployed container. Note that the nodejsmicro-k8s-service name was previously configured in the nodejs_micro.yaml file.

Note: The OCID for the cluster, mentioned in the script above, needs to be replaced by the one which you have. 


Click the Build Now button to start executing the Kubernetes deployment build. You can click the Build Log icon to view the build execution logs.


After the build job executes successfully, you can examine the build log to retrieve the IP address and the port for the deployed service on Kubernetes cluster. You’ll need to look for the IP address and the port under the deployment name you configured in the YAML file.


Use the IP address and the port that you retrieved in the format shown below and see the output in your browser.

http://<IP Address>:port/message

Note: The message output you see may differ from what is shown here, based on what you coded in the Node.js REST application that was containerized.


So, now you’ve seen how Oracle Developer Cloud streamlines and simplifies the process for managing the automation for building and deploying Docker containers on Oracle Kubernetes Engine.

Happy Coding!


**The views expressed in this post are my own and do not necessarily reflect the views of Oracle

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.