Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the Serverless tutorials #1476

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/user/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* [Create a Git Function](/serverless-manager/user/tutorials/01-11-create-git-function.md)
* [Expose the Function](/serverless-manager/user/tutorials/01-20-expose-function.md)
* [Manage Functions Through Kyma CLI](/serverless-manager/user/tutorials/01-30-manage-functions-with-kyma-cli.md)
* [Debug a Function](/serverless-manager/user/tutorials/01-40-debug-function.md)
* [Log Into a Private Package Registry](/serverless-manager/user/tutorials/01-80-log-into-private-packages-registry.md)
* [Set Asynchronous Communication Between Functions](/serverless-manager/user/tutorials/01-90-set-asynchronous-connection.md)
* [Customize Function Traces](/serverless-manager/user/tutorials/01-100-customize-function-traces.md)
Expand Down
21 changes: 14 additions & 7 deletions docs/user/tutorials/01-10-create-inline-function.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ To learn more about Function's signature, `event` and `context` objects, and cus
> [!NOTE]
> Read about [Istio sidecars in Kyma and why you want them](https://kyma-project.io/docs/kyma/latest/01-overview/service-mesh/smsh-03-istio-sidecars-in-kyma/). Then, check how to [enable automatic Istio sidecar proxy injection](https://kyma-project.io/docs/kyma/latest/04-operation-guides/operations/smsh-01-istio-enable-sidecar-injection/). For more details, see [Default Istio setup in Kyma](https://kyma-project.io/docs/kyma/latest/01-overview/service-mesh/smsh-02-default-istio-setup-in-kyma/).

## Steps
## Prerequisites

* You have the Serverless module added.

## Procedure

You can create a Function with Kyma dashboard, Kyma CLI, or kubectl:

Expand All @@ -21,12 +25,13 @@ You can create a Function with Kyma dashboard, Kyma CLI, or kubectl:

1. Create a namespace or select one from the drop-down list in the top navigation panel.

2. Go to **Workloads** > **Functions** and select **Create Function**.
2. Go to **Workloads** > **Functions** and choose **Create**.

3. In the dialog box, provide the Function's name or click on **Generate**.
3. In the dialog box, provide the Function's name.

> [!NOTE]
> The **Node.js Function** preset is selected by default. It means that the selected runtime is `Node.js`, and the **Source** code is autogenerated. You can choose the Python runtime by clicking on the **Choose preset** button.
4. Choose `JavaScript` from the **Language** dropdown.

5. Paste the following code snippet in the **Source** section, and choose **Create**.

```js
module.exports = {
Expand All @@ -41,9 +46,9 @@ You can create a Function with Kyma dashboard, Kyma CLI, or kubectl:
};
```

The dialog box closes. Wait for the **Status** field to change into `RUNNING`, confirming that the Function was created successfully.
Wait for the **Status** field to change into `RUNNING`, confirming that the Function was created successfully.

1. If you decide to modify it, click **Edit** and confirm changes afterward by selecting the **Update** button. You will see the message at the bottom of the screen confirming the Function was updated.
If you decide to modify your Function, click **Edit** and confirm changes afterward by selecting the **Save** button. You will see the message at the bottom of the screen confirming the Function was updated.

#### **Kyma CLI**

Expand All @@ -52,6 +57,7 @@ The dialog box closes. Wait for the **Status** field to change into `RUNNING`, c
```bash
export NAME={FUNCTION_NAME}
export NAMESPACE={FUNCTION_NAMESPACE}
export KUBECONFIG={PATH_TO_YOUR_KUBECONFIG}
```

2. Create your local development workspace.
Expand Down Expand Up @@ -107,6 +113,7 @@ The dialog box closes. Wait for the **Status** field to change into `RUNNING`, c
```bash
export NAME={FUNCTION_NAME}
export NAMESPACE={FUNCTION_NAMESPACE}
export KUBECONFIG={PATH_TO_YOUR_KUBECONFIG}
```

2. Create a Function CR that specifies the Function's logic:
Expand Down
20 changes: 13 additions & 7 deletions docs/user/tutorials/01-11-create-git-function.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ To learn more about Git repository sources for Functions and different ways of s
> [!NOTE]
> Read about [Istio sidecars in Kyma and why you want them](https://kyma-project.io/docs/kyma/latest/01-overview/service-mesh/smsh-03-istio-sidecars-in-kyma/). Then, check how to [enable automatic Istio sidecar proxy injection](https://kyma-project.io/docs/kyma/latest/04-operation-guides/operations/smsh-01-istio-enable-sidecar-injection/). For more details, see [Default Istio setup in Kyma](https://kyma-project.io/docs/kyma/latest/01-overview/service-mesh/smsh-02-default-istio-setup-in-kyma/).

## Steps
## Prerequisites

* You have the Serverless module added.

## Procedure

You can create a Function either with kubectl or Kyma dashboard:

Expand All @@ -24,9 +28,9 @@ You can create a Function either with kubectl or Kyma dashboard:

If you use a secured repository, you must first create a Secret with either basic (username and password or token) or SSH key authentication to this repository in the same namespace as the Function. To do that, follow these sub-steps:

- Open your namespace view. In the left navigation panel, go to **Configuration** > **Secrets** and select the **Create Secret** button.
- Open your namespace view. In the left navigation panel, go to **Configuration** > **Secrets** and choose **Create**.

- Open the **Advanced** view and enter the Secret name and type.
- Enter the Secret name and type.

- Under **Data**, enter these key-value pairs with credentials:

Expand All @@ -39,11 +43,11 @@ You can create a Function either with kubectl or Kyma dashboard:

- Confirm by selecting **Create**.

3. To connect the repository, go to **Workloads** > **Functions** > **Create Function**.
3. To connect the repository, go to **Workloads** > **Functions** > **Create**.

4. Provide or generate the Function's name.
4. Provide the Function's name.

5. Go to **Advanced**, change **Source Type** from **Inline** to **Git Repository**.
5. Change **Source Type** from **Inline** to **Git Repository**.

6. Choose `JavaScript` from the **Language** dropdown and select the proper runtime.

Expand All @@ -67,6 +71,7 @@ You can create a Function either with kubectl or Kyma dashboard:
```bash
export GIT_FUNCTION={GIT_FUNCTION_NAME}
export NAMESPACE={FUNCTION_NAMESPACE}
export KUBECONFIG={PATH_TO_YOUR_KUBECONFIG}
```

2. Create a Secret (optional).
Expand All @@ -76,7 +81,7 @@ You can create a Function either with kubectl or Kyma dashboard:
- Basic authentication (username and password or token) to this repository in the same namespace as the Function:

1. Generate a [personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic) and copy it.
2. Create a Secret containg your username and the generated token.
2. Create a Secret containing your username and the generated token.

```bash
kubectl -n $NAMESPACE create secret generic git-creds-basic --from-literal=username={GITHUB_USERNAME} --from-literal=password={GENERATED_PERSONAL_TOKEN}
Expand Down Expand Up @@ -125,6 +130,7 @@ You can create a Function either with kubectl or Kyma dashboard:
type: # "basic" or "key"
secretName: # "git-creds-basic" or "git-creds-ssh"
```

If you use the `key` type authentication, the SSH URL format must be used to configure the Function URL:

```yaml
Expand Down
56 changes: 41 additions & 15 deletions docs/user/tutorials/01-20-expose-function.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ Read also about [Function’s specification](../technical-reference/07-70-functi

## Prerequisites

- [Existing Function](01-10-create-inline-function.md)
- [API Gateway module added](https://kyma-project.io/docs/kyma/latest/04-operation-guides/operations/02-install-kyma/#install-specific-components)
- You have an [existing Function](01-10-create-inline-function.md)
- You have the API Gateway and Serverless modules added

## Steps
## Procedure

You can expose a Function using Kyma dashboard, Kyma CLI, or kubectl:

Expand All @@ -26,7 +26,7 @@ You can expose a Function using Kyma dashboard, Kyma CLI, or kubectl:

1. Select a namespace from the drop-down list in the top navigation panel. Make sure the namespace includes the Function that you want to expose using the APIRule CR.

2. Go to **Discovery and Network** > **API Rules**, and click on **Create API Rule**.
2. Go to **Discovery and Network** > **API Rules**, and choose **Create**.

3. Enter the following information:

Expand All @@ -49,21 +49,33 @@ You can expose a Function using Kyma dashboard, Kyma CLI, or kubectl:

#### **Kyma CLI**

1. Export these variables:
1. Run the following command to get the domain name of your Kyma cluster:

```bash
kubectl get gateway -n kyma-system kyma-gateway \
-o jsonpath='{.spec.servers[0].hosts[0]}'
```

2. Export the result without the leading `*.` as an environment variable:

```bash
export DOMAIN={DOMAIN_NAME}

3. Export these variables:

```bash
export NAME={FUNCTION_NAME}
export NAMESPACE={NAMESPACE_NAME}
export KUBECONFIG={PATH_TO_YOUR_KUBECONFIG}
```

2. Download the latest configuration of the Function from the cluster. This way, you update the local `config.yaml` file with the Function's code.
4. Download the latest configuration of the Function from the cluster. This way, you update the local `config.yaml` file with the Function's code.

```bash
kyma sync function $NAME -n $NAMESPACE
```

3. Edit the local `config.yaml` file and add the **apiRules** schema for the Function at the end of the file:
5. Edit the local `config.yaml` file and add the **apiRules** schema for the Function at the end of the file:

```yaml
apiRules:
Expand All @@ -80,45 +92,58 @@ You can expose a Function using Kyma dashboard, Kyma CLI, or kubectl:
- handler: no_auth
```

4. Apply the new configuration to the cluster:
6. Apply the new configuration to the cluster:

```bash
kyma apply function
```

5. Check if the Function's code was pushed to the cluster and reflects the local configuration:
7. Check if the Function's code was pushed to the cluster and reflects the local configuration:

```bash
kubectl get apirules $NAME -n $NAMESPACE
```

6. Check that the APIRule was created successfully and has the status `OK`:
8. Check that the APIRule was created successfully and has the status `OK`:

```bash
kubectl get apirules $NAME -n $NAMESPACE -o=jsonpath='{.status.APIRuleStatus.code}'
```

7. Call the Function's external address:
9. Call the Function's external address:

```bash
curl https://$NAME.$DOMAIN
```

If successful, the `Hello World!` message appears.

#### **kubectl**

1. Export these variables:
1. Run the following command to get the domain name of your Kyma cluster:

```bash
kubectl get gateway -n kyma-system kyma-gateway \
-o jsonpath='{.spec.servers[0].hosts[0]}'
```

2. Export the result without the leading `*.` as an environment variable:

```bash
export DOMAIN={DOMAIN_NAME}

3. Export these variables:

```bash
export NAME={FUNCTION_NAME}
export NAMESPACE={FUNCTION_NAMESPACE}
export KUBECONFIG={PATH_TO_YOUR_KUBECONFIG}
```

> [!NOTE]
> The APIRule CR can have a name different from that of the Function, but it is recommended that all related resources share a common name.

2. Create an APIRule CR, which exposes your Function on port `80`.
4. Create an APIRule CR, which exposes your Function on port `80`.

```bash
cat <<EOF | kubectl apply -f -
Expand All @@ -145,17 +170,18 @@ You can expose a Function using Kyma dashboard, Kyma CLI, or kubectl:
EOF
```

3. Check that the APIRule was created successfully and has the status `OK`:
5. Check that the APIRule was created successfully and has the status `OK`:

```bash
kubectl get apirules $NAME -n $NAMESPACE -o=jsonpath='{.status.APIRuleStatus.code}'
```

4. Access the Function's external address:
6. Access the Function's external address:

```bash
curl https://$NAME.$DOMAIN
```

If successful, the `Hello World!` message appears.

<!-- tabs:end -->
14 changes: 7 additions & 7 deletions docs/user/tutorials/01-30-manage-functions-with-kyma-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ Before you start, make sure you have these tools installed:

- [Docker](https://www.docker.com/)
- [Kyma CLI](https://github.com/kyma-project/cli)
- [Serverless module installed](https://kyma-project.io/docs/kyma/latest/04-operation-guides/operations/08-install-uninstall-upgrade-kyma-module/) locally or in a cluster
- Serverless module

## Steps
## Procedure

Follow these steps:

Expand All @@ -32,17 +32,17 @@ Follow these steps:
You can also use the `--dir {FULL_FOLDER_PATH}` flag to point to the directory where you want to create the Function's source files.

> [!NOTE]
> Python 3.9 is only one of the available runtimes. Read about all [supported runtimes and sample Functions to run on them](../technical-reference/07-10-sample-functions.md).
> Python 3.12 is only one of the available runtimes. Read about all [supported runtimes and sample Functions to run on them](../technical-reference/07-10-sample-functions.md).

The `init` command creates these files in your workspace folder:

- `config.yaml` with the Function's configuration
- `config.yaml` with the Function's configuration

> [!NOTE]
> See the detailed description of all fields available in the [`config.yaml` file](../technical-reference/07-60-function-configuration-file.md).

- `handler.py` with the Function's code and the simple "Hello World" logic
- `requirements.txt` with an empty file for your Function's custom dependencies
- `handler.py` with the Function's code and the simple "Hello World" logic
- `requirements.txt` with an empty file for your Function's custom dependencies

The `kyma init` command also sets **sourcePath** in the `config.yaml` file to the full path of the workspace folder:

Expand All @@ -55,7 +55,7 @@ Follow these steps:
sourcePath: {FULL_PATH_TO_WORKSPACE_FOLDER}
```

1. Run the `apply` Kyma CLI command to create a Function CR in the YAML format on your cluster:
2. Run the `apply` Kyma CLI command to create a Function CR in the YAML format on your cluster:

```bash
kyma apply function
Expand Down
Loading
Loading