Welcome to my GitHub

Github.com/zq2599/blog…

Content: all original article classification summary and supporting source code, involving Java, Docker, Kubernetes, DevOPS, etc.;

Links to OpenFaaS Field series articles

  1. The deployment of
  2. Introduction to the function
  3. Java functions
  4. Template operation (Template)
  5. Big watchdog
  6. Of -watchdog(For performance)
  7. Java11 template parsing
  8. Maven +jdk8
  9. Maven +maven+jdk8

About OpenFaaS

OpenFaaS is a Serverless framework from Docker community. Its function is to provide users with FaaS computing platform.www.openfaas.com, below from the official:

OpenFaaS In Action series

“OpenFaaS Actual Combat” series is another actual combat type of the original series, aimed to learn mainstream Serverless knowledge with readers through actual combat, toward the goal of learning to use, from the most basic deployment, and then gradually familiar with the advanced functions of OpenFaaS;

This paper gives an overview of

As the beginning of this series of articles, the main content of this article is the OpenFaaS environment setup and client tool installation and configuration, which is divided into the following parts:

  1. Environmental information
  2. Kubernetes deployment of OpenFaaS
  3. Deploy OpenFaaS
  4. Experience basic functions of OpenFaaS
  5. Install and configure the client

Environmental information

  • OpenFaaS used in the whole combat series are deployed in Kubernetes environment, so please prepare Kubernetes environment in advance;
  • The OpenFaaS architecture running in Kubernetes environment is shown in the figure below. Gateway and FaAS-Netes are two important components:

  • I here because is the development environment, so did not deploy Kubernetes cluster, but deployment of Kubernetes on a single machine;
  • The following is the version information of the environment and software involved in the whole series for your reference:
  1. OS: CentOS Linux release 7.8.2003
  2. Kubernetes: 1.18.6
  3. OpenFaaS gateway: 0.20.1
  4. OpenFaaS faas – netes: 0.12.8

Kubernetes deployment of OpenFaaS

Faas-netes is a sub-project of OpenFaaS, which is used to implement OpenFaaS functions in Kubernetes environment. There are three common deployment methods for Faas-Netes:

  1. Faas-netes GitHub repository already has all the required files for deployment, download it and use it directly.
  2. You can use HelM3 to deploy, although this method requires a good installation of HELM3, which is a bit troublesome, but you can modify the configuration file to achieve more fine-grained Settings;
  3. Using The Arkade tool, this will add to the learning cost, or later…
  • In order to quickly complete the deployment, this article chooses the first approach

The deployment of

Next download faas-Netes source code, using kubernetes resource configuration file for deployment;

  1. Install git command
yum install -y git
Copy the code
  1. Download the source code
git clone https://github.com/openfaas/faas-netes
Copy the code
  1. Go to the download folder
cd faas-netes
Copy the code
  1. Create a namespace
kubectl apply -f namespaces.yml
Copy the code
  1. The following information is displayed. You can see that two namespaces openfaas and OpenFaas-fn are created
[root@node1 faas-netes]# kubectl apply -f namespaces.yml
namespace/openfaas created
namespace/openfaas-fn created
Copy the code
  1. Set the account and password for logging in to the Web console. I use admin for the account and password
kubectl -n openfaas create secret generic basic-auth \
    --from-literal=basic-auth-user=admin \
    --from-literal=basic-auth-password=admin
Copy the code
  1. The deployment of
kubectl apply -f ./yaml/
Copy the code
  1. The console output shows that a large number of resources are being created:
[root@node1 faas-netes]# kubectl apply -f ./yaml/
configmap/alertmanager-config created
deployment.apps/alertmanager created
service/alertmanager created
deployment.apps/basic-auth-plugin created
service/basic-auth-plugin created
serviceaccount/openfaas-controller created
role.rbac.authorization.k8s.io/openfaas-controller created
role.rbac.authorization.k8s.io/openfaas-profiles created
rolebinding.rbac.authorization.k8s.io/openfaas-controller created
rolebinding.rbac.authorization.k8s.io/openfaas-profiles created
customresourcedefinition.apiextensions.k8s.io/profiles.openfaas.com created
deployment.apps/faas-idler created
deployment.apps/gateway created
service/gateway-external created
service/gateway created
deployment.apps/nats created
service/nats created
customresourcedefinition.apiextensions.k8s.io/profiles.openfaas.com configured
configmap/prometheus-config created
deployment.apps/prometheus created
serviceaccount/openfaas-prometheus created
clusterrole.rbac.authorization.k8s.io/openfaas-prometheus created
rolebinding.rbac.authorization.k8s.io/openfaas-prometheus created
rolebinding.rbac.authorization.k8s.io/openfaas-prometheus created
service/prometheus created
deployment.apps/queue-worker created
Copy the code
  1. During startup, each pod is unstable. In case of both CrashLoopBackOff and Error like the following, it is recommended to wait a few minutes and the pod will return to normal after several automatic restarts:
[root@node1 faas-netes]# kubectl get pods -n openfaas NAME READY STATUS RESTARTS AGE alertmanager-dc4b8b67b-m8pkx 1/1 Running 0 66s basic-auth-plugin-7bb7698cb4-d6zkl 1/1 Running 0 66s faas-idler-df8c6d98d-p726g 0/1 CrashLoopBackOff 1 66s  gateway-775db4dbd4-dcvx9 1/2 Error 0 66s nats-58d4d5db8d-km9jf 1/1 Running 0 66s prometheus-8689d7dc98-dmjvs 1/1 Running 0 58s queue-worker-5b4db6776f-hzl5q 1/1 Running 0 59sCopy the code
  1. After the image download, POD creation, and startup are complete, the example situation is as follows:
[root@node1 faas-netes]# kubectl get pods -n openfaas
NAME                                 READY   STATUS    RESTARTS   AGE
alertmanager-dc4b8b67b-kl4wq         1/1     Running   0          10m
basic-auth-plugin-7bb7698cb4-ln6fx   1/1     Running   0          10m
faas-idler-df8c6d98d-xn68z           1/1     Running   2          10m
gateway-775db4dbd4-7l9h4             2/2     Running   1          10m
nats-58d4d5db8d-z7zzt                1/1     Running   0          10m
prometheus-8689d7dc98-9lk8t          1/1     Running   0          10m
queue-worker-5b4db6776f-nl999        1/1     Running   0          10m
Copy the code
  1. Gateway service is mapped to port 31222:
[root@node1 faas-netes]# kubectl get service -n openfaas NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE alertmanager ClusterIP 10.233.27.131 < None > 9093/TCP 13m Basic-auth-plugin ClusterIP 10.233.21.234 < None > 8080/TCP 13M Gateway ClusterIP 10.233.34.151 < None > 8080/TCP 13m gateway-External NodePort 10.233.62.82 < None > 8080:31112/TCP 13m nats ClusterIP 10.233.28.109 < None > 4222/TCP 13m Prometheus ClusterIP 10.233.60.220 < None > 9090/TCP 13mCopy the code

Now that the deployment is complete, verify that the environment is available

validation

  1. The current IP address of K8S host is 192.168.133.164, so the browser visits 192.168.133.164:31112, as shown in the picture below, the account and password input window will pop up. The account is admin, and the password is also admin:

2. Login is successful:

  1. Select NodeInfo, which provides basic information about the current server, and click on the “DEPLOY NEW FUNCTION” button in the red box below:

  1. This function is already in place, and the online verification is shown in the following image. It is extremely simple and can be invoked with a click of the mouse (the content in red box 2 is not currently needed, and will be used later) :

The address in red box 2 in the figure above is the endpoint of this function. Access this address in the browser, as shown in the following figure, can be successfully called:

Deploy and configure command line tools

Command-line tools are also very important, although they are not used in this chapter.

  1. The tool can be installed on other computers, as long as network access to the K8S environment is ok;
  2. Deployment can be completed with a single command:
curl -sL https://cli.openfaas.com | sh
Copy the code
  1. The command line deployment is successful if the following output is displayed:
Finding Latest Version from GitHub 0.12.18 Downloading Package https://github.com/openfaas/faas-cli/releases/download/0.12.18/faas-cli as/TMP/faas - cli Download complete. Running with  sufficient permissions to attempt to move faas-cli to /usr/local/bin New version of faas-cli installed to /usr/local/bin Creating alias 'faas' for 'faas-cli'. ___ _____ ____ / _ \ _ __ ___ _ __ | ___|_ _ __ _/ ___| | | | | '_ \ / _ \ '_ \ | | _ / _ ` | / _ ` \ _ \ | | _ | | | | __ _) / | | | | - (_ | | (_ | | ___) | \ ___ / | __ / \ ___ _ - | | | _ _ - | | \ __, _ | \ __, _ | ____ / | _ | CLI: commit: 9 e3c15ef3ad7bd7cceb0cd577144aebb50c6681c version: 0.12.18Copy the code
  1. Run the following command to write OPENFAAS_URL to the environment variable. 192.168.133.187 is the K8S host IP address:
Echo export OPENFAAS_URL=192.168.133.187:31112 >> ~/. BashrcCopy the code
  1. Then run source ~/.bashrc for the previous configuration to take effect immediately.
  2. Run the following command to log in using your account and password:
faas-cli login -u admin -p admin
Copy the code
  1. The login is successful and you can execute the client command. The list command output is as follows:
[root@node1 ~]# faas-cli list
Function                      	Invocations    	Replicas
nodeinfo                      	2              	1
Copy the code

Clean up the

If you do not want to use OpenFaaS and need to clean Up OpenFaaS thoroughly, perform the following operations:

  1. Access the faas-netes directory
  2. The account password
kubectl delete secret basic-auth -n openfaas
Copy the code
  1. Resource file
kubectl delete -f ./yaml
Copy the code
  1. Namespace openfaas-fn
kubectl delete namespace openfaas-fn
Copy the code
  1. Namespace Openfaas
kubectl delete namespace openfaas
Copy the code

In the next chapter, we will focus on the functional capabilities of OpenFaaS.

You are not alone, Xinchen original accompany all the way

  1. Java series
  2. Spring series
  3. The Docker series
  4. Kubernetes series
  5. Database + middleware series
  6. The conversation series

Welcome to pay attention to the public number: programmer Xin Chen

Wechat search “programmer Xin Chen”, I am Xin Chen, looking forward to enjoying the Java world with you…

Github.com/zq2599/blog…