Kyma functions are managed custom resources in the underlying SAP Kyma Runtime k8s cluster. There are two ways of managing functions source code: either using the inline editor or with a git repository. While the inline source code is a perfect choice for quick prototyping it lacks versioning and is not suitable for continuous development/integration. |
I shall demonstrate how to create a secure git repository connection to a kyma nodejs function source code using SSH keypair. I shall also showcase how to extend the definition of a function object by adding environment variables into a config map. Good to know:
|
| |
$ ls ~/.ssh/id_rsa
/Users/<userid>/.ssh/id_rsa
$ kubectl -n default create secret generic git-creds-key3 --from-file=key=/Users/<userid>/.ssh/id_rsa --kubeconfig ~/.kube/kubeconfig.yaml
secret/git-creds-key3 created
Git Repository (with public SSH key) | Kyma namespace (with private SSH key) |
Goto repository main branch level and retrieve the SSH connection string as the URL of your repository connection. | Goto Workloads/Functions/Repositories/Connect Repository |
kubectl get crd gitrepositories.serverless.kyma-project.io -o yaml --kubeconfig ~/.kube/kubeconfig.yaml
$ kubectl apply -n default --kubeconfig ~/.kube/kubeconfig.yaml -f - <<EOF
apiVersion: v1
kind: Secret
metadata:
name: git-creds-key3
namespace: default
type: Opaque
data:
key: LS0tLS1CRUdJTUFBQUVibTl1W0hQUklWQVRFS0VZLS0tLS0=
EOF
secret/git-creds-key2 created
$ kubectl apply -n default --kubeconfig ~/.kube/kubeconfig.yaml -f - <<EOF
apiVersion: serverless.kyma-project.io/v1alpha1
kind: GitRepository
metadata:
name: poster
namespace: default
spec:
url: "git@github.com:<repo root>/RTH10.git"
auth:
type: "key"
secretName: "git-creds-key3"
EOF
gitrepository.serverless.kyma-project.io/poster created
$ kubectl apply -n default --kubeconfig ~/.kube/kubeconfig.yaml -f - <<EOF
apiVersion: serverless.kyma-project.io/v1alpha1
kind: Function
metadata:
name: demo-poster
namespace: default
spec:
labels:
podLabel1: data1
minReplicas: 1
maxReplicas: 1
type: git # git repo function
runtime: nodejs14 # function runtime
source: poster # git repo connection name
reference: main # git repo branch name
baseDir: /demo/poster # directory path to function source code
env:
- name: "DATA"
value: "123"
- name: DATA_FROM_CM
valueFrom:
configMapKeyRef:
name: demo-poster
key: superData
- name: DATA2_FROM_CM
valueFrom:
configMapKeyRef:
name: demo-poster
key: superData2
- name: DATA3_FROM_CM
valueFrom:
configMapKeyRef:
name: demo-poster
key: superData3
---
apiVersion: v1
kind: ConfigMap
metadata:
name: demo-poster
data:
superData:
"{}"
superData2:
"{}"
superData3:
"{}"
EOF
function.serverless.kyma-project.io/demo-poster created
configmap/demo-poster created
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
24 | |
8 | |
7 | |
7 | |
6 | |
6 | |
6 | |
6 | |
5 | |
5 |