Manage Functions with Kyma CLI ​
This tutorial shows how to use the available CLI commands to manage Functions in Kyma. You will see how to:
- Generate local files that contain source code and dependencies for a sample "Hello World" Python Function (
kyma function init). - Create a Function custom resource (CR) from these files and apply it on your cluster (
kyma function create). - List all Function CRs from the cluster (
kyma function get). - Delete previously created Function CR from the cluster (
kyma function delete).
This tutorial is based on a sample Python Function run in a lightweight k3d cluster.
Prerequisites ​
Before you start, make sure you have these tools installed:
Procedure ​
Follow these steps:
- To create local files with the default configuration for a Python Function, go to the folder in which you want to initiate the workspace content and run the
initKyma CLI command:
kyma function init pythonYou 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.12 is only one of the available runtimes. Read about all supported runtimes and sample Functions to run on them.
The init command creates these files in your workspace folder:
handler.py- the Function's code and the simple "Hello World" logicrequirements.txt- an empty file for your Function's custom dependenciesAfter your files are successfully created, you will see the following output message with suggestions on how you can run the code:
textNext steps: * update output files in your favorite IDE * create Function, for example: kyma function create python my-python-fn --source handler.py --dependencies requirements.txtNOTE
Now is a good time to customize your Python runtimes source code. You can do it by editing generated files in your favorite editor.
- Run the
createKyma CLI command to create a Function CR in the YAML format in your cluster based on the suggestion from the previous command:
kyma function create python my-python-fn --source handler.py --dependencies requirements.txt- Once applied, check the Function's state in the cluster:
kyma function get- Delete Function from the cluster:
kyma function delete {FUNCTION_NAME}