1. Install PFS using this url for minikube. Refer to these instructions to install PFS on minikube
https://docs.pivotal.io/pfs/install-on-minikube.html
2. Once installed verify PFS has been installed using some commands as follows
$ watch -n 1 kubectl get pod --all-namespaces
Output:
Various namespaces are created as shown below:
$ kubectl get namespaces
NAME STATUS AGE
default Active 19h
istio-system Active 18h
knative-build Active 18h
knative-eventing Active 18h
knative-serving Active 18h
kube-public Active 19h
kube-system Active 19h
Ensure PFS is installed as shown below:
$ pfs version
Version
pfs cli: 0.1.0 (e5de84d12d10a060aeb595310decbe7409467c99)
3. Now we are going to deploy this employee function which exists on GitHub as follows
https://github.com/papicella/emp-function-service
The Function code is as follows:
package com.example.empfunctionservice; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import java.util.function.Function; @Slf4j @SpringBootApplication public class EmpFunctionServiceApplication { private static EmployeeService employeeService; public EmpFunctionServiceApplication(EmployeeService employeeService) { this.employeeService = employeeService; } @Bean public Function<String, String> findEmployee() { return id -> { String response = employeeService.getEmployee(id); return response; }; } public static void main(String[] args) { SpringApplication.run(EmpFunctionServiceApplication.class, args); } }
4. We are going to deploy a Spring Boot Function as per the REPO above. More information on Java Functions for PFS can be found here
https://docs.pivotal.io/pfs/using-java-functions.html
5. Let's create a function called "emp-function" as shown below
$ pfs function create emp-function --git-repo https://github.com/papicella/emp-function-service --image $REGISTRY/$REGISTRY_USER/emp-function -w -v
Output: (Just showing the last few lines here)
papicella@papicella:~/pivotal/software/minikube$ pfs function create emp-function --git-repo https://github.com/papicella/emp-function-service --image $REGISTRY/$REGISTRY_USER/emp-function -w -v
Waiting for LatestCreatedRevisionName
Waiting on function creation: checkService failed to obtain service status for observedGeneration 1
LatestCreatedRevisionName available: emp-function-00001
...
default/emp-function-00001-gpn7p[build-step-build]: [INFO] BUILD SUCCESS
default/emp-function-00001-gpn7p[build-step-build]: [INFO] ------------------------------------------------------------------------
default/emp-function-00001-gpn7p[build-step-build]: [INFO] Total time: 12.407 s
default/emp-function-00001-gpn7p[build-step-build]: [INFO] Finished at: 2019-01-22T00:12:39Z
default/emp-function-00001-gpn7p[build-step-build]: [INFO] ------------------------------------------------------------------------
default/emp-function-00001-gpn7p[build-step-build]: Removing source code
default/emp-function-00001-gpn7p[build-step-build]:
default/emp-function-00001-gpn7p[build-step-build]: -----> riff Buildpack 0.1.0
default/emp-function-00001-gpn7p[build-step-build]: -----> riff Java Invoker 0.1.3: Contributing to launch
default/emp-function-00001-gpn7p[build-step-build]: Reusing cached download from buildpack
default/emp-function-00001-gpn7p[build-step-build]: Copying to /workspace/io.projectriff.riff/riff-invoker-java/java-function-invoker-0.1.3-exec.jar
default/emp-function-00001-gpn7p[build-step-build]: -----> Process types:
default/emp-function-00001-gpn7p[build-step-build]: web: java -jar /workspace/io.projectriff.riff/riff-invoker-java/java-function-invoker-0.1.3-exec.jar $JAVA_OPTS --function.uri='file:///workspace/app'
default/emp-function-00001-gpn7p[build-step-build]: function: java -jar /workspace/io.projectriff.riff/riff-invoker-java/java-function-invoker-0.1.3-exec.jar $JAVA_OPTS --function.uri='file:///workspace/app'
default/emp-function-00001-gpn7p[build-step-build]:
...
default/emp-function-00001-deployment-66fbd6bf4-bbqpq[user-container]: Hibernate: insert into employee (id, name) values (null, ?)
default/emp-function-00001-deployment-66fbd6bf4-bbqpq[user-container]: 2019-01-22 00:13:53.617 INFO 1 --- [ Thread-4] c.e.empfunctionservice.LoadDatabase : Preloading Employee(id=1, name=pas)
default/emp-function-00001-deployment-66fbd6bf4-bbqpq[user-container]: Hibernate: insert into employee (id, name) values (null, ?)
default/emp-function-00001-deployment-66fbd6bf4-bbqpq[user-container]: 2019-01-22 00:13:53.623 INFO 1 --- [ Thread-4] c.e.empfunctionservice.LoadDatabase : Preloading Employee(id=2, name=lucia)
default/emp-function-00001-deployment-66fbd6bf4-bbqpq[user-container]: Hibernate: insert into employee (id, name) values (null, ?)
default/emp-function-00001-deployment-66fbd6bf4-bbqpq[user-container]: 2019-01-22 00:13:53.628 INFO 1 --- [ Thread-4] c.e.empfunctionservice.LoadDatabase : Preloading Employee(id=3, name=lucas)
default/emp-function-00001-deployment-66fbd6bf4-bbqpq[user-container]: Hibernate: insert into employee (id, name) values (null, ?)
default/emp-function-00001-deployment-66fbd6bf4-bbqpq[user-container]: 2019-01-22 00:13:53.632 INFO 1 --- [ Thread-4] c.e.empfunctionservice.LoadDatabase : Preloading Employee(id=4, name=siena)
default/emp-function-00001-deployment-66fbd6bf4-bbqpq[user-container]: 2019-01-22 00:13:53.704 INFO 1 --- [ Thread-2] o.s.c.f.d.FunctionCreatorConfiguration : Located bean: findEmployee of type class com.example.empfunctionservice.EmpFunctionServiceApplication$$Lambda$791/373359604
pfs function create completed successfully
6. Let's invoke our function as shown below by returning each Employee record using it's ID.
$ pfs service invoke emp-function --text -- -w '\n' -d '1'
curl http://192.168.64.3:32380/ -H 'Host: emp-function.default.example.com' -H 'Content-Type: text/plain' -w '\n' -d 1
Employee(id=1, name=pas)
$ pfs service invoke emp-function --text -- -w '\n' -d '2'
curl http://192.168.64.3:32380/ -H 'Host: emp-function.default.example.com' -H 'Content-Type: text/plain' -w '\n' -d 2
Employee(id=2, name=lucia)
The "pfs service invoke" will show you what an external command will look like to invoke the function service. The IP address here is just the same IP address returned by "minikube ip" as shown below.
$ minikube ip
192.168.64.3
7. Let's view our services using "pfs" CLI
$ pfs service list
NAME STATUS
emp-function Running
hello Running
pfs service list completed successfully
8. Invoking from Postman, ensuring we issue a POST request and pass the correct headers as shown below
More Information
https://docs.pivotal.io/pfs/index.html
No comments:
Post a Comment