You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2019/10/04 21:11:25 UTC

[GitHub] [openwhisk] chetanmeh opened a new pull request #4671: Standalone OpenWhisk KubernetesContainerFactory support

chetanmeh opened a new pull request #4671: Standalone OpenWhisk KubernetesContainerFactory support
URL: https://github.com/apache/openwhisk/pull/4671
 
 
   Enables support for configuring `KubernetesContainerFactory` (KCF) with Standalone OpenWhisk for simplified local development for KCF.
   
   ## Description
   
   To simplify developing on KCF locally this PR adds support for configuring KCF via `--dev-kcf` flag. 
   
   ### Local Port Forwardning
   
   To enable this mode a new config option is added to enable port forwarding
   
   ```
   wsk {
     kubernetes {
       # Enables forwarding to remote port via a local random port. This mode is mostly useful
       # for development via Standalone mode
       port-forwarding-enabled = false
     }
   }
   ```
   
   If this mode is enabled then after launching a pod a local port forward would be enabled and that port would then be used by `ContainerProxy` to communicate with the pod running with k8s
   
   ### Usage
   
   To try out this feature
   
   #### 1. Install and configure Kind
   
   We would use [Kind][1] to setup a local k8s. Follow the steps [here][1] to create a simple cluster
   
   ```bash
   $ kind create cluster --wait 5m
   
   # Export the kind config for kubectl usage
   $ export KUBECONFIG="$(kind get kubeconfig-path)"
   
   # Configure the default namespace
   $ kubectl config set-context --current --namespace=default
   
   # See the config path
   $ kind get kubeconfig-path
   /Users/chetanm/.kube/kind-config-kind
   ```
   
   #### 2. Launch Standalone 
   
   ```bash
   
   # Build the standalone jar
   $ ./gradlew :core:standalone:build
   
   # Launch it with `kubeconfig` system property set to kind config
   $ java  -Dkubeconfig="$(kind get kubeconfig-path)" -jar bin/openwhisk-standalone.jar --dev-kcf
   ```
   
   Once started and required `.wskprops` configured (see standalone startup logs for details) create a `hello.js` function
   
   ```js
   function main(params) {
       greeting = 'hello, world'
       var hello = {payload: greeting}
       var result = {...hello, ...process.env}
       console.log(greeting);
       return result
   }
   ```
   
   ```bash
   $ wsk action create hello hello.js
   $ wsk action invoke hello -br
   ```
   
   This shows an output like below
   
   ```json
   {
       "HOME": "/root",
       "HOSTNAME": "wsk0-2-prewarm-nodejs10",
       "KUBERNETES_PORT": "tcp://10.96.0.1:443",
       "KUBERNETES_PORT_443_TCP": "tcp://10.96.0.1:443",
       "KUBERNETES_PORT_443_TCP_ADDR": "10.96.0.1",
       "KUBERNETES_PORT_443_TCP_PORT": "443",
       "KUBERNETES_PORT_443_TCP_PROTO": "tcp",
       "KUBERNETES_SERVICE_HOST": "10.96.0.1",
       "KUBERNETES_SERVICE_PORT": "443",
       "KUBERNETES_SERVICE_PORT_HTTPS": "443",
       "NODE_VERSION": "10.15.3",
       "PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
       "PWD": "/nodejsAction",
       "YARN_VERSION": "1.13.0",
       "__OW_ACTION_NAME": "/guest/hello",
       "__OW_ACTIVATION_ID": "71e48d2d62e142eca48d2d62e192ec2d",
       "__OW_API_HOST": "http://host.docker.internal:3233",
       "__OW_DEADLINE": "1570223213407",
       "__OW_NAMESPACE": "guest",
       "__OW_TRANSACTION_ID": "iSOoNklk6V7l7eh8KJnvugidKEmaNJmv",
       "payload": "hello, world"
   }
   ```
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services