Monday, December 3, 2018

Setting up fn on Kubernetes in the Oracle Cloud (OKE)

In this post I will briefly describe how you can install fn on Kubernetes in the Oracle Cloud (OKE).

Prerequisites

  1. You need to have access to Oracle Cloud Infrastructure (OCI) with a unique account. If you have a federated account, you should create another one to be able to create a kubernetes cluster. This account must have either Administrator privileges or belong to a group to which a policy grants the appropriate Container Engine for Kubernetes permissions. Since my example is for R&D purposes, I will be using an account with Administrator privileges.
  2. Install and configure the OCI CLI, generate an API signing key pair and add that public key to your username. 
  3. Create a separate compartment for the cluster and make sure your compartment has the necessary resources and your root compartments needs the policy Allow service OKE to manage all-resources in tenancy 
  4. Install and setup kubectl on Windowns (tip: use Chocolatey)
  5. Install helm

Create the Kubernetes cluster

  1. Navigate to your console
  2. Under Developer Services, select "clusters"
  3. Pick the compartment that you created or want to use
  4. Click on "Create Cluster" and accept all the defaults
  5. Click "Create"
  6. Inspect the details 
  7. Download the kubeconfig file and store it in your .kube directory
If it fails because of service limits, raise an SR with Oracle support to get your limits increased.

Install fn 

  1. Make sure your server version of helm is up to date (helm init --upgrade)
  2. Create a directory fnhelm
  3. Clone the git repo: git clone https://github.com/fnproject/fn-helm.git
  4. Install the chart dependencies: helm dep build fn
  5. Install it in your cluster: helm install --name my-release fn

Deploy your function to the cluster

  1. Make sure you are logged in to your dockerhub account
  2. Set the fn context to the right value
  3. Deploy the function to the cluster

The fn context

When you use fn deploy, it uses a context to determine where to deploy to, and what registry to use. The URL for the fnserver you deployed to the kubernetes cluster  can be found by issuing the following command

  • $(kubectl get svc --namespace default my-release-fn-api -o jsonpath='{.status.loadBalancer.ingress[0].ip}'):80
However, you can also look it up using a kubectl proxy: 
  • kubectl proxy 
  • Navigate to a browser: https://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/#
  • Select "Services" in the navigation menu at the left


  • Click on the External Endpoint of the my-release-fn-api 
  • You should see the following:
Now we can create the context by running the following commands:
  • fn list contexts
  • fn create context ociLonneke --api-url [your url] --provider default --registry [your_dockerhub_username]
  • fn list contexts

Deploy the function to the cluster

Finally! We are ready to deploy our first function to our cluster. In this case I use the Java tutorial example. 
  • fn init --runtime java --trigger http javafn
  • fn build
  • fn deploy --app java-app
This will result in the following output (or something similar)

Successfully created app:  java-app
Successfully created function: javafn with lonneke/javafn:0.0.2
Successfully created trigger: javafn-trigger
Trigger Endpoint: http://xxx.xx.xx.xx:80/t/java-app/javafn-trigger

Test the function

Open a browser and type the url as stated by the trigger endpoint. You should see the following result:

Next steps

Now you have your kubernetes cluster up and running, you can move your functions from your local installation to the cluster and start using them in production!

Happy coding 😊














No comments:

Post a Comment