Giter Club home page Giter Club logo

openfunction-samples's Introduction

OpenFunction Samples

Installation

Version

  • OpenFunction v0.4.0

Setup a Cluster

minikube start -p demo --kubernetes-version=v1.22.2 --network-plugin=cni --cni=calico

Install OpenFunction

# clone repo
git clone https://github.com/OpenFunction/OpenFunction.git

# enter the repo
cd openfunction

# install the prerequisties
sh hack/deploy.sh --all

# verification of dapr
dapr status -k
# install openfunction
kubectl create -f https://github.com/OpenFunction/OpenFunction/releases/download/v0.4.0/bundle.yaml

# verfication
kubectl get pods --namespace openfunction

Uninstall OpenFunction

# delete openfunction
kubectl delete -f https://raw.githubusercontent.com/OpenFunction/OpenFunction/release-0.4/config/bundle.yaml

# delete the prerequisties
sh hack/delete.sh --all

How to deploy a function

Create a push secret

REGISTRY_SERVER=https://index.docker.io/v1/
REGISTRY_USER=<your_registry_user>
REGISTRY_PASSWORD=<your_registry_password>
kubectl create secret docker-registry push-secret \
    --docker-server=$REGISTRY_SERVER \
    --docker-username=$REGISTRY_USER \
    --docker-password=$REGISTRY_PASSWORD

Deploy a Function

cd hello-world-go
kubectl create -f hello-world-go.yaml

View the Function

❯ kubectl get functions
NAME              BUILDSTATE   SERVINGSTATE   BUILDER         SERVING   AGE
function-sample   Created                     builder-6bf2s             61s

Check the building process

❯ kubectl get builders
NAME            PHASE   STATE      AGE
builder-6bf2s   Build   Building   70s

❯ kubectl get builds
NAME                        REGISTERED   REASON      BUILDSTRATEGYKIND      BUILDSTRATEGYNAME   CREATIONTIME
builder-cvkrg-build-5lz4g   True         Succeeded   ClusterBuildStrategy   openfunction        16m

❯ kubectl get ClusterBuildStrategies
NAME           AGE
openfunction   3h37m

❯ kubectl get buildruns
NAME                           SUCCEEDED   REASON    STARTTIME   COMPLETIONTIME
builder-pzdgk-buildrun-jrkpz   Unknown     Running   103s

❯ kubectl get taskruns
NAME                                 SUCCEEDED   REASON    STARTTIME   COMPLETIONTIME
builder-pzdgk-buildrun-jrkpz-8q4cx   Unknown     Running   108s

Once the function is built, the relative CR will be cleaned.

View the Serving

❯ kubectl get servings
NAME            PHASE     STATE     AGE
serving-q9dsr   Serving   Running   20s

❯ kubectl get ksvc
NAME                       URL                                                   LATESTCREATED                   LATESTREADY                     READY   REASON
serving-q9dsr-ksvc-77w9x   http://serving-q9dsr-ksvc-77w9x.default.example.com   serving-q9dsr-ksvc-77w9x-v100   serving-q9dsr-ksvc-77w9x-v100   True

Port-forward the ingress gateway

kubectl port-forward --namespace kourier-system svc/kourier 8080:80

Curl from ingress gateway with HOST Header

export INGRESS_HOST=localhost
export INGRESS_PORT=8080
SERVICE_NAME=serving-q9dsr-ksvc-77w9x
SERVICE_HOSTNAME=$(kubectl get ksvc $SERVICE_NAME -n default -o jsonpath='{.status.url}' | cut -d "/" -f 3)
curl -v -H "Host: $SERVICE_HOSTNAME" http://$INGRESS_HOST:$INGRESS_PORT

View the Pod

❯ kubectl get pods
NAME                                                        READY   STATUS    RESTARTS   AGE
serving-q9dsr-ksvc-77w9x-v100-deployment-78f557b95b-9j66b   2/2     Running   0          28s

Delete the Function

kubectl delete -f hello-world-go.yaml

How to debug

Build failed

Check the Builder

❯ kubectl get builders
NAME            PHASE   STATE    AGE
builder-qx8w5   Build   Failed   11h

❯  kubectl get builders -o yaml
apiVersion: v1
items:
- apiVersion: core.openfunction.io/v1alpha2
  kind: Builder
  metadata:
    creationTimestamp: "2021-11-23T14:58:29Z"
    generateName: builder-
    generation: 1
    labels:
      openfunction.io/function: hello-world-python
    name: builder-qx8w5
    namespace: default
    ownerReferences:
    - apiVersion: core.openfunction.io/v1alpha2
      blockOwnerDeletion: true
      controller: true
      kind: Function
      name: hello-world-python
      uid: 9ec1a8a9-2b05-4117-a87a-c1a2e35a36f1
    resourceVersion: "4232427"
    uid: 9b689181-30b4-40f9-b2af-0973784abd17
  spec:
    builder: openfunction/builder:v1
    env:
      FUNC_NAME: hello_world
      FUNC_SRC: main.py
      FUNC_TYPE: http
    image: lizzzcai/sample-python-func:v0.4.0
    imageCredentials:
      name: push-secret
    port: 8080
    srcRepo:
      sourceSubPath: hello-world-python
      url: https://github.com/lizzzcai/openfunction-samples.git
  status:
    phase: Build
    resourceRef:
      shipwright.io/build: builder-qx8w5-build-mn97k
      shipwright.io/buildRun: builder-qx8w5-buildrun-x6q7b
    state: Failed
kind: List
metadata:
  resourceVersion: ""
  selfLink: ""

Check the Build

❯  kubectl get build
NAME                        REGISTERED   REASON      BUILDSTRATEGYKIND      BUILDSTRATEGYNAME   CREATIONTIME
builder-qx8w5-build-mn97k   True         Succeeded   ClusterBuildStrategy   openfunction        11h

Check the BuildRun

❯  kubectl get buildrun
NAME                           SUCCEEDED   REASON   STARTTIME   COMPLETIONTIME
builder-qx8w5-buildrun-x6q7b   False       Failed   11h         11h

❯  kubectl get buildrun -o yaml
apiVersion: v1
items:
- apiVersion: shipwright.io/v1alpha1
  kind: BuildRun
  metadata:
    creationTimestamp: "2021-11-23T14:58:29Z"
    generateName: builder-qx8w5-buildrun-
    generation: 1
    labels:
      build.shipwright.io/generation: "1"
      build.shipwright.io/name: builder-qx8w5-build-mn97k
      openfunction.io/builder: builder-qx8w5
    name: builder-qx8w5-buildrun-x6q7b
    namespace: default
    ownerReferences:
    - apiVersion: core.openfunction.io/v1alpha2
      blockOwnerDeletion: true
      controller: true
      kind: Builder
      name: builder-qx8w5
      uid: 9b689181-30b4-40f9-b2af-0973784abd17
    resourceVersion: "4232426"
    uid: b6309378-c55b-4ff3-b514-b410d6a42b29
  spec:
    buildRef:
      name: builder-qx8w5-build-mn97k
  status:
    buildSpec:
      builder:
        image: openfunction/builder:v1
      output:
        credentials:
          name: push-secret
        image: lizzzcai/sample-python-func:v0.4.0
      paramValues:
      - name: APP_IMAGE
        value: lizzzcai/sample-python-func:v0.4.0
      - name: ENV_VARS
        value: FUNC_NAME=hello_world#FUNC_SRC=main.py#FUNC_TYPE=http#PORT=8080
      source:
        contextDir: hello-world-python
        url: https://github.com/lizzzcai/openfunction-samples.git
      strategy:
        kind: ClusterBuildStrategy
        name: openfunction
    completionTime: "2021-11-23T14:58:47Z"
    conditions:
    - lastTransitionTime: "2021-11-23T14:58:48Z"
      message: 'buildrun step step-create failed in pod builder-qx8w5-buildrun-x6q7b-bnbl6-pod-l4kwf,
        for detailed information: kubectl --namespace default logs builder-qx8w5-buildrun-x6q7b-bnbl6-pod-l4kwf
        --container=step-create'
      reason: Failed
      status: "False"
      type: Succeeded
    failedAt:
      container: step-create
      pod: builder-qx8w5-buildrun-x6q7b-bnbl6-pod-l4kwf
    latestTaskRunRef: builder-qx8w5-buildrun-x6q7b-bnbl6
    startTime: "2021-11-23T14:58:30Z"
kind: List
metadata:
  resourceVersion: ""
  selfLink: ""

Check the logs

❯ kubectl --namespace default logs builder-qx8w5-buildrun-x6q7b-bnbl6-pod-l4kwf --container=step-create
===> DETECTING
======== Error: [email protected] ========
chdir /workspace/source/hello-world-python: no such file or directory
======== Error: [email protected] ========
chdir /workspace/source/hello-world-python: no such file or directory
...

Check the TaskRun

❯ kubectl get taskruns
NAME                                 SUCCEEDED   REASON   STARTTIME   COMPLETIONTIME
builder-qx8w5-buildrun-x6q7b-bnbl6   False       Failed   11h         11h

Check the TaskRun in Tekton Dashboard

Install the latest release of Tekton Dashboard

kubectl apply --filename https://github.com/tektoncd/dashboard/releases/latest/download/tekton-dashboard-release.yaml

Set up port forwarding with Tekton Dashboard

kubectl --namespace tekton-pipelines port-forward svc/tekton-dashboard 9097:9097

Once set up, the dashboard is available in the browser under the address http://localhost:9097.

Reference

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.