github.com/iron-io/functions@v0.0.0-20180820112432-d59d7d1c40b2/docs/operating/kubernetes/README.md (about)

     1  # HOWTO run IronFunction in Kubernetes at AWS
     2  
     3  *Prerequisite 1: it assumes you have a working Kubernetes, and a locally configured kubectl.*
     4  
     5  *Prerequisite 2: It assumes you are using Kubernetes 1.4 or newer.*
     6  
     7  
     8  ## Quickstart
     9  
    10  ### Steps
    11  
    12  1. Start IronFunction in the Kubernetes cluster:
    13  ```ShellSession
    14  $ cd docs/operating/kubernetes
    15  $ kubectl create -f kubernetes-quick
    16  ```
    17  
    18  2. Once the daemon is started, check where it is listening for connections:
    19  
    20  ```ShellSession
    21  # kubectl describe svc functions
    22  
    23  Name:			functions
    24  Namespace:		default
    25  Labels:			app=functions
    26  Selector:		app=functions
    27  Type:			LoadBalancer
    28  IP:			10.0.116.122
    29  LoadBalancer Ingress:	a23122e39900111e681ba0e29b70bb46-630391493.us-east-1.elb.amazonaws.com
    30  Port:			<unset>	8080/TCP
    31  NodePort:		<unset>	30802/TCP
    32  Endpoints:		10.244.1.12:8080
    33  Session Affinity:	None
    34  Events:
    35    FirstSeen	LastSeen	Count	From			SubobjectPath	Type		Reason			Message
    36    ---------	--------	-----	----			-------------	--------	------			-------
    37    22m		22m		1	{service-controller }			Normal		CreatingLoadBalancer	Creating load balancer
    38    22m		22m		1	{service-controller }			Normal		CreatedLoadBalancer	Created load balancer
    39  
    40  ```
    41  
    42  Note `a23122e39900111e681ba0e29b70bb46-630391493.us-east-1.elb.amazonaws.com` in `LoadBalancer Ingress` line, this is where the service is listening.
    43  
    44  3. Test the cluster:
    45  
    46  ```ShellSession
    47  $ export IRON_FUNCTION=$(kubectl get -o json svc functions | jq -r '.status.loadBalancer.ingress[0].hostname'):8080
    48  
    49  $ curl -H "Content-Type: application/json" -X POST -d '{ "app": { "name":"myapp" } }' http://$IRON_FUNCTION/v1/apps
    50  {"message":"App successfully created","app":{"name":"myapp","config":null}}
    51  
    52  $ curl -H "Content-Type: application/json" -X POST -d '{ "route": { "type": "sync", "path":"/hello-sync", "image":"iron/hello" } }' http://$IRON_FUNCTION/v1/apps/myapp/routes
    53  {"message":"Route successfully created","route":{"app_name":"myapp","path":"/hello-sync","image":"iron/hello","memory":128,"type":"sync","config":null}}
    54  
    55  $ curl -H "Content-Type: application/json" -X POST -d '{ "name":"Johnny" }' http://$IRON_FUNCTION/r/myapp/hello-sync
    56  Hello Johnny!
    57  ```
    58  
    59  ## Production
    60  
    61  ### Steps
    62  
    63  1. Start IronFunction and its dependencies:
    64  ```ShellSession
    65  $ cd docs/
    66  $ kubectl create -f kubernetes-production
    67  ```
    68  
    69  *Optionally, you might have both Redis and PostgreSQL started somewhere else, in this case, remember to update kubernetes-production/functions-config.yaml with the appropriate configuration.*
    70  
    71  2. Once the daemon is started, check where it is listening for connections:
    72  
    73  ```ShellSession
    74  # kubectl describe svc functions
    75  
    76  Name:			functions
    77  Namespace:		default
    78  Labels:			app=functions
    79  Selector:		app=functions
    80  Type:			LoadBalancer
    81  IP:			10.0.116.122
    82  LoadBalancer Ingress:	a23122e39900111e681ba0e29b70bb46-630391493.us-east-1.elb.amazonaws.com
    83  Port:			<unset>	8080/TCP
    84  NodePort:		<unset>	30802/TCP
    85  Endpoints:		10.244.1.12:8080
    86  Session Affinity:	None
    87  Events:
    88    FirstSeen	LastSeen	Count	From			SubobjectPath	Type		Reason			Message
    89    ---------	--------	-----	----			-------------	--------	------			-------
    90    22m		22m		1	{service-controller }			Normal		CreatingLoadBalancer	Creating load balancer
    91    22m		22m		1	{service-controller }			Normal		CreatedLoadBalancer	Created load balancer
    92  
    93  ```
    94  
    95  Note `a23122e39900111e681ba0e29b70bb46-630391493.us-east-1.elb.amazonaws.com` in `LoadBalancer Ingress` line, this is where the service is listening.
    96  
    97  3. Test the cluster:
    98  
    99  ```ShellSession
   100  $ export IRON_FUNCTION=$(kubectl get -o json svc functions | jq -r '.status.loadBalancer.ingress[0].hostname'):8080
   101  
   102  $ curl -H "Content-Type: application/json" -X POST -d '{ "app": { "name":"myapp" } }' http://$IRON_FUNCTION/v1/apps
   103  {"message":"App successfully created","app":{"name":"myapp","config":null}}
   104  
   105  $ curl -H "Content-Type: application/json" -X POST -d '{ "route": { "type": "sync", "path":"/hello-sync", "image":"iron/hello" } }' http://$IRON_FUNCTION/v1/apps/myapp/routes
   106  {"message":"Route successfully created","route":{"app_name":"myapp","path":"/hello-sync","image":"iron/hello","memory":128,"type":"sync","config":null}}
   107  
   108  $ curl -H "Content-Type: application/json" -X POST -d '{ "name":"Johnny" }' http://$IRON_FUNCTION/r/myapp/hello-sync
   109  Hello Johnny!
   110  ```