You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/openfaas-pro/function-crd.md
+72-29Lines changed: 72 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,16 +2,17 @@
2
2
3
3
In addition to the REST API of the OpenFaaS gateway, the `Function` Custom Resource Definition can be used to manage functions.
4
4
5
-
Glossary:
5
+
Q: What's the difference between a Custom Resource Definition (CRD) and a Custom Resource (CR)?
6
+
A: The CRD is the definition of a Function, which is installed to the cluster once via helm when OpenFaaS is installed The CR is an instance of a Function.
6
7
7
-
* CRD - the definition of a Function, the Custom Resource Definition (CRD) is installed to the cluster via Helm, once.
8
-
* Each instance of a Function is called a Custom Resource (CR).
8
+
Q: Do you still need stack.yml, if we want to adopt the Function CRD?
9
+
A: We recommend using either stack.yml on its own, along with IAM for OpenFaaS. However, if you want to use Helm, ArgoCD or Flux for GitOps-style deployments, then we would recommend using stack.yml for local development and for building images during CI, and the Function CRD for deployment.
9
10
10
-
!!! warning "Do not remove the CRD"
11
+
Q: Can GitOps be used with Functions CRs?
12
+
A: You can use Helm, ArgoCD, or FluxCD to template, update and deploy functions. The Function CRD is a native Kubernetes resource, so it can be managed in the same way as Deployments, Services, and other resources.
11
13
12
-
Do not remove the Custom Resource Definition from the cluster.
13
-
14
-
If you remove the Function CRD, then all instances of the CRD (known as CRs) will be removed from the cluster, meaning all your functions will be deleted immediately.
14
+
Q: Can I still use kubectl if I deploy functions via REST or `faas-cli`?
15
+
A: Yes, the REST API accepts JSON deployment requests and then creates and manages a Function CR behind the scenes for you. That means you can explore, backup and inspect Functions using kubectl, even if you are not deploying via kubectl directly.
15
16
16
17
See also:
17
18
@@ -20,6 +21,12 @@ See also:
20
21
21
22
### Function Spec
22
23
24
+
!!! warning "Do not remove the CRD"
25
+
26
+
Do not remove the Custom Resource Definition from the cluster.
27
+
28
+
If you remove the Function CRD, then all instances of the CRD (known as CRs) will be removed from the cluster, meaning all your functions will be deleted immediately.
29
+
23
30
Here is an example of a function, written out in long form:
24
31
25
32
```yaml
@@ -53,7 +60,64 @@ spec:
53
60
- nodeinfo-secret1
54
61
```
55
62
56
-
## How to generate a spec from a stack.yml
63
+
### How to query Functions with kubectl
64
+
65
+
Create a function using the following YAML:
66
+
67
+
```yaml
68
+
cat << EOF | kubectl apply -f -
69
+
apiVersion: openfaas.com/v1
70
+
kind: Function
71
+
metadata:
72
+
name: env
73
+
namespace: openfaas-fn
74
+
spec:
75
+
name: env
76
+
image: ghcr.io/openfaas/alpine:latest
77
+
environment:
78
+
fprocess: "env"
79
+
EOF
80
+
```
81
+
82
+
Then watch the status:
83
+
```bash
84
+
$ kubectl get function--watch --output wide --namespace openfaas-fn
85
+
86
+
NAME IMAGE READY HEALTHY REPLICAS AVAILABLE
87
+
env ghcr.io/openfaas/alpine:latest
88
+
env ghcr.io/openfaas/alpine:latest
89
+
env ghcr.io/openfaas/alpine:latest True False
90
+
env ghcr.io/openfaas/alpine:latest True False 1
91
+
env ghcr.io/openfaas/alpine:latest True False 1
92
+
env ghcr.io/openfaas/alpine:latest True True 1 1
93
+
```
94
+
95
+
* Replicas represents the desired state, this starts as either 1 or the value of the `com.openfaas.min.scale` label. This value may also be changed by the autoscaler.
96
+
* Available represents the actual number of Pods that are ready to serve traffic, that have passed their readiness check.
97
+
98
+
### Readiness and health
99
+
100
+
The OpenFaaS REST API contains readiness information in the form of available replicas being > 0. The `faas-cli` also has a `describe` command which queries the amount of available replicas and will report Ready or Not Ready.
101
+
102
+
That said, the Custom Resource now has a `.status` field with a number of conditions.
103
+
104
+
*`Reconciling` is `True` - the operator has discovered the Function CR and is working on creating child resources in Kubernetes
105
+
*`Stalled` is `True` - the operator cannot create the function, check the reason, perhaps some secrets are missing?
106
+
*`Ready` condition is `True` - the operator was able to create the required Deployment, all required secrets exist, and it has no more work to do. The `Reconciling` condition is removed
107
+
*`Healthy` condition is `True` - there is at least one ready Pod available to serve traffic
108
+
109
+
What about scaling to zero? When a Function is scaled to zero, the Ready state will be `True` and the Healthy state will be `False`. Invoke the function via its URL on the gateway to have it scale up from zero, you'll see it progress and gain a `Healthy` condition of `True`.
110
+
111
+
If you change a Function once it has passed into the Ready=true state, then the Ready condition will change to Unknown, and the Reconciling condition will be added again.
112
+
113
+
If you're an ArgoCD user, then you can define a custom health check at deployment time to integrate with the Custom Resource: [ArgoCD: Custom Health Checks](https://argo-cd.readthedocs.io/en/stable/operator-manual/health/#custom-health-checks)
114
+
115
+
To check that all secrets existed, and that the function could be applied correctly, then look for a `Ready` condition with a status of `True` for the current generation of the object. If you want to know if the function's code was valid, and was able to start, and that its image could be pulled, look for the `Healthy` condition instead. Bear in mind that any functions scaled to zero may have the Healthy condition removed, or set to False.
116
+
117
+
What happens when auto-scaling? When a Function is scaling from at least one replica to some higher number, the Healthy condition will continue to be set to `True`. The same applies when scaling down, so long as the target number of replicas is greater than zero.
118
+
119
+
120
+
### How to generate a spec from a stack.yml
57
121
58
122
If you already have functions defined in a stack.yml file, you can generate the Function resources with:
59
123
@@ -116,27 +180,6 @@ Therefore, in CI, you may run something like:
The OpenFaaS REST API contains readiness information in the form of available replicas being > 0. The `faas-cli` also has a `describe` command which queries the amount of available replicas and will report Ready or Not Ready.
122
-
123
-
That said, the Custom Resource now has a `.status` field with a number of conditions.
124
-
125
-
*`Reconciling` is `True` - the operator has discovered the Function CR and is working on creating child resources in Kubernetes
126
-
*`Stalled` is `True` - the operator cannot create the function, check the reason, perhaps some secrets are missing?
127
-
*`Ready` condition is `True` - the operator was able to create the required Deployment, all required secrets exist, and it has no more work to do. The `Reconciling` condition is removed
128
-
*`Healthy` condition is `True` - there is at least one ready Pod available to serve traffic
129
-
130
-
What about scaling to zero? When a Function is scaled to zero, the Ready state will be `True` and the Healthy state will be `False`. Invoke the function via its URL on the gateway to have it scale up from zero, you'll see it progress and gain a `Healthy` condition of `True`.
131
-
132
-
If you change a Function once it has passed into the Ready=true state, then the Ready condition will change to Unknown, and the Reconciling condition will be added again.
133
-
134
-
If you're an ArgoCD user, then you can define a custom health check at deployment time to integrate with the Custom Resource: [ArgoCD: Custom Health Checks](https://argo-cd.readthedocs.io/en/stable/operator-manual/health/#custom-health-checks)
135
-
136
-
To check that all secrets existed, and that the function could be applied correctly, then look for a `Ready` condition with a status of `True` for the current generation of the object. If you want to know if the function's code was valid, and was able to start, and that its image could be pulled, look for the `Healthy` condition instead. Bear in mind that any functions scaled to zero may have the Healthy condition removed, or set to False.
137
-
138
-
What happens when auto-scaling? When a Function is scaling from at least one replica to some higher number, the Healthy condition will continue to be set to `True`. The same applies when scaling down, so long as the target number of replicas is greater than zero.
139
-
140
183
### Deploy functions via Helm
141
184
142
185
You can template and deploy functions via Helm, ArgoCD and Flux by including the Function's CR YAML in the same way you would for any other native Kubernetes resource.
0 commit comments