Skip to content

Oracle Cloud Developer Workshop - Microservice Helidon CD with Oracle Pipeline and Oracle Engine for Kubernetes (OKE)

Notifications You must be signed in to change notification settings

pasimoes/oracledev-microservice-k8s-workshop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Oracle Cloud Developer Workshop - Microservice Helidon CD with Oracle Pipeline and Oracle Engine for Kubernetes (OKE)

Before You Begin

This workshop shows you how to using Oracle Pipeline (Wercker) to construct and push Docker images to OCI Registry and deploy the image as a container to an existing OCI Container Engine for Kubernetes (OKE) cluster.

Background

As part of the Development process, developers write new code, and merge their code back into the master (source code). In this tutorial, the repository of this source code is GitHub.

Wercker is integrated into GitHub so that, for example, when there is a commit (new code, or changes are made to a branch or the master), Wercker can automatically build a container image.

In the case of a commit to master, Wercker runs a pipeline and builds the image, pushes the image to OCIR and then deploys the container to an instance of OKE, replacing the running containers/pods, and thus updating the application.

What Do You Need?

• Complete the tutorial Creating a Cluster with Oracle Cloud Infrastructure Container Engine for Kubernetes and Deploying a Sample App

• GitHub Account

• Wercker Account Wercker App

Workshop parameters

Clone Helidon Microservice application

In this section, you create a Wercker application of a GitHub application.

  1. Login to your GitHub account. Open the application Helidon Microservice in Github and click Fork.

Helidon QuickStart SE Project Fork

  1. Adjust Application Name on following files:

    Where quickstart-se include your participant number, for example quickstart-se01

    • kubernetes_deployment.yml.template

    Adjust on K8s Deployment Template

    • kubernetes_service.yml.template

    Adjust on K8s Service Template

    • wercker.yml

    Adjust on Wercker yml

  2. Select the wercker.yml file to open it.

  3. Any Docker Image created by the Wercker application will be tagged with the corresponding Git commit that triggered its run. This is a Wercker best practice that ensures a given revision of your source is included in a known single artifact image. This aids in observability as well as making it easy to point Kubernetes at new changes to the application. The environment variables that need to be passed to Wercker will be:

    • OCIR_USERNAME
    • OCIR_PASSWORD
    • OCIR_REPO
    • OCIR_ADDR

Create Wercker application

  1. Open and login to your Wercker account. Click on + option and choose Add application .

Wercker Add Application

  1. Make sure your user is selected for #1 and GitHub is selected for #2 and click Next.

Wercker Create New Application Step 1

  1. Select the helidon-quickstart-se application you previously forked and click Next.

Wercker Create New Application Step 2

  1. Accept the default to checkout the code and click Next.

Wercker Create New Application Step 3

  1. Click Create.

Wercker Create New Application Step 4

  1. Your application was created successfully. In the next section, you define the environment variables. Click the Environment tab.

Wercker Define Environment Variables

Set Application Environment Variables

  1. Create each of the following environment variables and click Add after each one.

    • OCI Registry Username must include the <tenancy name>/<username>
    • OCI Registry Password is the auth_token for your cluster. Click Protected checkbox. NOTE: It must not contain a $ character.
    • OCI Registry Repo must include <region-code>.ocir.io/<tenancy name>/<registry name>
    • OCI Registry Address When done, click the Run tab.

Wercker Define Environment Variables

  1. Test that the application can be built and pushed to OCIR. Navigate to Runs tab and Click the trigger a build now link at the bottom of the page.

Wercker Run 01

Wercker Run 02

  1. The build is completed successfully.

Wercker Run 03

Configure Cluster to Pull Images from OCI Registry

In order for the images to pulled during deployment, you need to configure the cluster by creating an image secret and setting some additional parameters in your Wercker application.

  1. The Kubernetes configuration file references the image secret using the environment variable OKE_IMAGESECRET which you need to create as an environment variable in your Wercker application.

    • Key: OKE_IMAGESECRET (provided by the instructor)
  2. Switch to Wercker click the Environment tab.

  3. Enter the Key OKE_IMAGESECRET and Value <secret name> and click Add.

  4. Repeat the inclusion of parameters :

    • Key: OKE_MASTER (provided by the instructor)
    • Key: OKE_TOKEN (provided by the instructor)

Wercker Define Environment Variables

  1. To review the script when a deploy to kubernetes is performed, switch to GitHub and open the wercker.yml file.

  2. Scroll to the deploy-to-kubernetes area. The first step is that all the .template extensions are removed. Then it will move all the Kubernetes configuration files to a clean directory for consumption by kubectl commands.

  3. These steps in the configuration file do the following:

    • Set a timeout on the deployment of 60 seconds, giving the deployment time to successfully start the application's container before timing out.
    • Watch the status of the deployment until all pods have come up. If the timeout is hit this will immediately return a non zero exit code and cause the pipeline run to fail. This means your pipeline will succeed only if your application has been successfully deployed, otherwise it fails

Wercker Build Automatic

Add Workflow to Pipeline in Wercker Application

To deploy the OCI Container Engine for Kubernetes (OKE), you need to create a Deploy-to-Kubernetes workflow in your Wercker application.

  1. Switch to your Wercker application and on the Workflows tab. Click Add New Pipeline.

Wercker Workflow New Pipeline

  1. Enter deploy-to-kubernetes for both Name and YML Pipeline name and click Create.

Wercker Workflow Config Pipeline

  1. Click the Workflows tab.

  2. In the Workflow Editor, click the ' + ', to create a new pipeline chain after the build. Select deploy-to-kubernetes for Execute pipeline and click Add.

Wercker Workflow Exec Pipeline

Wercker Workflow Exec Pipeline Config

  1. The new change in the workflow was created successfully. In the next section, you deploy the OCI image to kubernetes.

Deploy the OCI Container to OCI Container Engine for Kubernetes

  1. Switch to Runs tab. Click on the last build pipeline to show its execution. On Actions button Click deploy-to-kubernetes The deployment pipeline starts and perform the deployment of the container to OKE.

Wercker Deploy Pipeline

Wercker Deploy Pipeline Execution

  1. Your deployment completed successfully.

Wercker Deploy Pipeline Execution Successful 02

Wercker Deploy Pipeline Execution Successful 03

Wercker Deploy Pipeline Execution Successful 04

Verifying Service in OCI Container Engine for Kubernetes

You can verify the service by running the app in OCI Container Engine for Kubernetes .

Access from Container Native Terminal on OCI.

For participants that don't have OCI Cli and Kubectl installed, we prepared some Container Native Terminals.

$ ssh opc@<node-address> -i <ssh-key> [opc@oracledev ~]$

  1. From your terminal window, execute the following:

    export KUBECONFIG=~/kubeconfig
    kubectl get services
    
  2. Paste the value for EXTERNAL-IP into your browser to run the application.

  3. Assemble the url to access the helloworld application, in the form http://<node-address>:<port-number>. Obtain the values of <node-address> and <port-number> from the Kubernetes Dashboard as follows:

    • To find out the <node-address>, consult information about the pod running the quickstart-se app, and obtain the address of the node running it from the NODE column. For example, 132.145.140.4.
        $ kubectl get pods --output=wide
        NAME                                    READY   STATUS    RESTARTS   AGE   IP            NODE
        hello-k8s-deployment-6dcbb9998b-jps7d   1/1     Running   0          8d    10.244.1.2    132.145.140.4
        quickstart-se-7bcfd74777-8rt4b          1/1     Running   0          1h    10.244.1.11   132.145.140.4
    

kubectl show pods

- To find out the ``<port-number>``, consult information about the **quickstart-se**, and obtain the port that the service is running on from the PORT(S) column. For example, port 30151.
```
    $ kubectl get services quickstart-se
    NAME            TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
    quickstart-se   NodePort   10.96.137.252   <none>        8090:30151/TCP   1h
```

kubectl show service details

  1. Open a new browser window and enter the url to access the quickstart-se application in the browser's URL field. For example, the full url might look like http://132.145.140.4:31030/greet

    When the browser loads the page, the page shows a message like: {"message":"Hello World!"}

microservice running 01

Now let's practice Continuous Delivery

The pipeline automatically starts when you make a change to one of your application files in GitHub.

  1. Switch to your GitHub application and select the GreetService.java file.

helidon update 01

  1. Edit the file.

  2. Scroll down to the getDefaultMessagemethod and change the word "World" to your message. Enter a description for commit and click Commit changes.

helidon update 02

helidon update 03

  1. Your change was commited. Switch to Wercker and click the Runs tab.

    • Note that the pipeline was executed automatically.

    helidon update 04

    • After the build completes the deploy workflow runs.
  2. Your deployment completed successfully. Click deploy-to-kubernetes to view the details.

    • Scroll to the bottom to verify that all the steps completed successfully.
  3. Open a new browser window and enter the url to access the quickstart-se application in the browser's URL field. For example, the full url might look like http://132.145.140.4:31030/greet

    When the browser loads the page, the page shows a message like: {"message":"Hello Brasil!"}

microservice running 03

Congratulations! You've successfully deployed the Helidon Quick Start Microservice onto a node in the new cluster, and verified that the application is working as expected.

About

Oracle Cloud Developer Workshop - Microservice Helidon CD with Oracle Pipeline and Oracle Engine for Kubernetes (OKE)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published