Register a service
This guide shows you how to register a service of your external solution in Kyma. For this example, we use a Basic Authentication-secured API.
Prerequisites
Before you start, expose the following as environment variables:
- Your Application name
- Username and password to access the external system
- Name of the Secret containing the service credentials
- Name of your service
- URL to your service
- Unique ID identifying your service within the Application CR
- Relative path in your service
- Namespace in which to create a test Pod
Click to copyexport APP_NAME=test-appexport USER_NAME=test-userexport PASSWORD=test-passwordexport SECRET_NAME=test-secretexport SERVICE_DISPLAY_NAME=test-basic-authexport TARGET_URL=https://httpbin.org/export TARGET_UUID=f03aafcc-85ad-4665-a46a-bf455f5fa0b3export TARGET_PATH=basic-auth/$USER_NAME/$PASSWORDexport NAMESPACE=defaultNOTE: Replace the example values above with your actual values.
Enable Istio sidecar injection in the Namespace:
Click to copykubectl label namespace $NAMESPACE istio-injection=enabled
Register a service
Create a Secret that contains your username and password to the external service:
Click to copykubectl create secret generic $SECRET_NAME --from-literal username=$USER_NAME --from-literal password=$PASSWORD -n kyma-systemTo register a service with a Basic Authentication-secured API, you must create or modify the respective Application CR. To create an Application CR with the service definition, run this command:
Click to copycat <<EOF | kubectl apply -f -apiVersion: applicationconnector.kyma-project.io/v1alpha1kind: Applicationmetadata:name: $APP_NAMEspec:skipVerify: falseservices:- id: $TARGET_UUIDname: $SERVICE_DISPLAY_NAMEdisplayName: $SERVICE_DISPLAY_NAMEdescription: "Your service"providerDisplayName: "Your organisation"entries:- credentials:secretName: $SECRET_NAMEtype: BasictargetUrl: $TARGET_URLtype: APIEOF
Access the registered service
To check that the service was registered correctly, create a test Pod, and make a call to Application Gateway from within this Pod.
To build a path to access your registered service, run this command:
Click to copyexport GATEWAY_URL=http://central-application-gateway.kyma-system:8080/$APP_NAME/$SERVICE_DISPLAY_NAME/$TARGET_PATHCAUTION:
SERVICE_DISPLAY_NAME
in the GATEWAY_URL path must be in its normalized form. This means that, for example, if you usedtest-basic-auth
as the service displayName, you're good to go, but if you used"Test Basic Auth"
, you must replace it withtest-basic-auth
in the path.Export the name of the test Pod as an environment variable:
Click to copyexport POD_NAME=test-app-gatewayCreate a test Pod:
Click to copycat <<EOF | kubectl apply -f -apiVersion: v1kind: Podmetadata:labels:run: $POD_NAMEname: $POD_NAMEnamespace: $NAMESPACEspec:containers:- image: busyboxname: $POD_NAMEresources: {}tty: truestdin: truednsPolicy: ClusterFirstrestartPolicy: Neverstatus: {}EOFWait for the Pod to be in state
Running
. To check that the Pod is ready, run this command and wait for the response:Click to copykubectl wait --for=condition=Ready pod $POD_NAME -n $NAMESPACETo make a call to Application Gateway from within the Pod, run:
Click to copykubectl exec $POD_NAME -c $POD_NAME -n $NAMESPACE -- sh -c "wget -O- '$GATEWAY_URL'"A successful response from the service means that it was registered correctly.