Here you will see how to deploy your serverless function to SAP BTP, Kyma Enviroment. One will be for public repositories and the another will be for private repositories using kubectl commands.
apiVersion: serverless.kyma-project.io/v1alpha2
kind: Function
metadata:
name: name-of-your-function
namespace: name-of-your-namespace
spec:
runtime: nodejs16
source:
gitRepository:
baseDir: /functions
reference: master
url: https://github.com/ericcarickli/kyma-serverless-function.git- Create a secret in your Kyma Runtime:
To generate a create secret kubectl command using your PRIV_KEY you can run the following command:
kubectl create secret generic name-of-your-secret --from-literal=key="SSH_PRIV_KEY" -o yaml --dry-run=clientThe previous command will generate a code like this:
apiVersion: v1
data:
key: your-encrypted-ssh-key
kind: Secret
metadata:
name: name-of-your-secret- Create your function in Kyma Runtime:
apiVersion: serverless.kyma-project.io/v1alpha2
kind: Function
metadata:
name: name-of-your-function
namespace: name-of-your-namespace
spec:
runtime: nodejs16
source:
gitRepository:
url: git@github.com:ericcarickli/kyma-serverless-function.git
baseDir: /functions
reference: master
auth:
type: key
secretName: name-of-your-secret- Create API Rule to expose your serverless function for http access:
apiVersion: gateway.kyma-project.io/v1beta1
kind: APIRule
metadata:
name: name-of-your-function-api
labels:
app.kubernetes.io/name: name-of-your-function-api
annotations: {}
namespace: default
spec:
gateway: kyma-gateway.kyma-system.svc.cluster.local
rules:
- path: /.*
methods:
- GET
accessStrategies:
- handler: allow
service:
name: name-of-your-function
port: 80
host: name-of-your-function-api.a217eee.kyma.ondemand.comNow your able to access your serverless function running in the url:
https://name-of-your-function-api.a217eee.kyma.ondemand.coma. Adding it to a .yaml file and running it with the command:
kubectl apply -n default -f your-file.yaml --kubeconfig ~/.kube/kubeconfig.yamlb. Running it inside of a cat <<EOF | EOF, for example:
cat <<EOF | kubectl apply --kubeconfig ~/.kube/kubeconfig.yaml -f -
apiVersion: v1
data:
key: your-encrypted-ssh-key
kind: Secret
metadata:
name: name-of-your-secret
EOFTo connect your local kubectl to your Kyma Runtime environment you can follow the steps in this link https://developers.sap.com/tutorials/cp-kyma-download-cli.html.