Skip to content

Commit 6849165

Browse files
committed
Consume SAP BTP Services In SAP Kyma
1 parent 0ff37c7 commit 6849165

5 files changed

Lines changed: 280 additions & 0 deletions

File tree

Lines changed: 280 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,280 @@
1+
---
2+
parser: v2
3+
auto_validation: true
4+
time: 30
5+
tags: [ tutorial>beginner, topic>cloud, software-product>sap-business-technology-platform]
6+
primary_tag: software-product>sap-btp\\, kyma-runtime
7+
---
8+
9+
# Consume SAP BTP Services In SAP Kyma
10+
<!-- description --> Build an Extension Application on Kyma using SAP BTP services.
11+
12+
## Prerequisites
13+
- Get an Account on SAP BTP to Try Out Free Tier Service Plans.[Get an Account on SAP BTP](btp-free-tier-account)
14+
- You have a Kyma-runtime environment on SAP Business Technology Platform (BTP) [Enable SAP BTP, Kyma-Runtime](cp-kyma-getting-started).
15+
- You have installed [Docker](https://docs.docker.com/get-started/#download-and-install-docker).
16+
- You have [Docker Hub](https://hub.docker.com/) account.
17+
- You have installed [Kubernetes command-line tool](https://kubernetes.io/docs/tasks/tools/#kubectl).
18+
- You've installed `kubectl CLI`, including the plugin `kubectl oidc-login` for authentication. See [Installing the Kubernetes Command Line Tool](cp-kyma-download-cli).
19+
- In addition, we recommend [`krew`](https://krew.sigs.k8s.io/docs/user-guide/setup/install/) to install and use the `kubectl` plugin for `Kubernetes OpenID Connect (OIDC)` authentication, also known as `kubectl oidc` plugin.
20+
- You have an [account on the SAP Gateway Demo System (ES5)](gateway-demo-signup) created
21+
- You have [connected SAP BTP to your SAP Gateway Demo System (ES5) account](cp-portal-cloud-foundry-gateway-connection).
22+
23+
## You will learn
24+
- How to consume SAP BTP services in sap Kyma-runtime
25+
- How to deploy applications into Kyma-runtime
26+
- How to use SAP BTP APIs, Service Manager and Service Operator to consume services from other environments
27+
- How to create service instances using sap-btp-service-operator [Working with SAP BTP Service Operator](https://help.sap.com/viewer/09cc82baadc542a688176dce601398de/Cloud/en-US/b5a35bfa87b5444080e6e6e6d361fa20.html).
28+
In this tutorial, we use the simple **`fiori`** sample application to learn some best practices to setting up your Kyma-runtime And communicate with SAP BTP so you can use the Destination and the SAP Authorization & Trust Management services.
29+
30+
---
31+
32+
### Download the Kyma runtime kubeconfig
33+
34+
35+
The `kubectl` tool relies on a configuration file called the `kubeconfig`, to configure access to the cluster. This step details how this can be obtained from both the BTP Cockpit and the Console UI.
36+
37+
To obtain the `kubeconfig` from the SAP BTP Cockpit:
38+
39+
1. Within your BTP account, navigate to the sub-account where the Kyma-runtime is enabled.
40+
41+
2. Choose the menu option **Overview**
42+
43+
3. Scroll down to the **Kyma-Environment** details
44+
45+
4. Choose the link next to **`KubeconfigURL`** to download the `kubeconfig`
46+
47+
![kubeconfig](kubeconfig-btp.png)
48+
49+
To obtain the `kubeconfig` from the Console UI:
50+
51+
1. Navigate to the Console UI of your Kyma-runtime.
52+
53+
2. Log onto the Kyma-runtime.
54+
55+
3. At the top-left of the Kyma-runtime window you will find a drop down which displays the name of the currently connected runtime.
56+
57+
4. Select the drop down and choose the option **Clusters Overview**
58+
59+
![cluster-overviews](cluster-overviews.png)
60+
61+
5. Choose the **`Download Kubeconfig`** option to download the file.
62+
63+
![kubeconfig](kubeconfig-ui.png)
64+
65+
66+
67+
### Set the KUBECONFIG environment variable
68+
69+
70+
To configure the access to your Kyma-runtime cluster, you have to set the `kubeconfig` environment variable to point to the location of the `kubeconfigfile` downloaded from your Kyma-runtime cluster.
71+
72+
[OPTION BEGIN [Mac and Linux]]
73+
74+
1. Open a command line prompt on your computer. In the command line screen, type in the following:
75+
76+
```Shell/Bash
77+
export KUBECONFIG=<KUBECONFIG_FILE_PATH>
78+
```
79+
80+
Replace the `<KUBECONFIG_FILE_PATH>` section with the file path, including the file name and extension, of the `Kubeconfig` you downloaded in the previous step.
81+
82+
2. Test the configuration by running this command:
83+
84+
```Shell/Bash
85+
kubectl config get-contexts
86+
```
87+
88+
This should return a response similar to:
89+
90+
|CURRENT|NAME|CLUSTER|AUTHINFO|NAMESPACE|
91+
|-------|----|-------|--------|---------|
92+
|* | `shoot--kyma-stage--c-#######`|`shoot--kyma-stage--c-#######`|`shoot--kyma-stage--c-#######`| |
93+
94+
3. You are now set up to use the Kyma-runtime on SAP BTP Platform.
95+
96+
[OPTION END]
97+
98+
[OPTION BEGIN [Windows]]
99+
100+
1. Open a command line prompt on your computer. In the command line screen, type in the following:
101+
102+
```PowerShell
103+
$ENV:KUBECONFIG="<KUBECONFIG_FILE_PATH>"
104+
```
105+
106+
```DOS
107+
set KUBECONFIG="<KUBECONFIG_FILE_PATH>"
108+
```
109+
110+
Replace the `<KUBECONFIG_FILE_PATH>` section with the file path, including the file name and extension, of the `Kubeconfig` you downloaded in the previous step.
111+
112+
2. Test the configuration by running this command:
113+
114+
```Shell/Bash
115+
kubectl config get-contexts
116+
```
117+
118+
This should return a response similar to:
119+
120+
|CURRENT|NAME|CLUSTER|AUTHINFO|NAMESPACE|
121+
|-------|----|-------|--------|---------|
122+
|* | `shoot--kyma-stage--c-#######`|`shoot--kyma-stage--c-#######`|`shoot--kyma-stage--c-#######`| |
123+
124+
3. You are now set up to use the Kyma-runtime on SAP BTP Platform.
125+
126+
[OPTION END]
127+
128+
129+
### Create service instances
130+
131+
132+
In the **`fioriapp`** sample application, the Destination and the SAP Authorization & Trust Management services will be consumed in Kyma-runtime. To use these SAP BTP services you have to create the respective service instances and service bindings. Use the `createservice.yaml` file which will create the `destination` service instance with plan `lite` and the `xsuaa` service instance with plan `application`.
133+
134+
1. The applications can be found in the [btp-hyperscaler-extension]
135+
(https://github.com/SAP-samples/btp-hyperscaler-extension) repository. Within the repo you can find each of their Deployment files within the respective folder.
136+
137+
2. Download the code by choosing the green **Code** button and then choosing one of the options to download the code locally.
138+
139+
You can instead run the following command within your CLI at your desired folder location:
140+
141+
```Shell/Bash
142+
git clone https://github.com/SAP-samples/btp-hyperscaler-extension
143+
```
144+
3. Create your own `sapfiori` namespace in your `Kyma cluster`.
145+
146+
```Shell/Bash
147+
kubectl create namespace sapfiori
148+
```
149+
> Note: Incase of login fails run command "kubectl krew install oidc-login".
150+
151+
4. Replace the `<Custom-Domain>` in `<Folder path>/btp-hyperscaler-extension/kyma/createservice.yaml` file.
152+
153+
Find your Cluster-domain and replace in the Createservice.yaml, run the below command and copy the `Kubernetes control pane` URL
154+
155+
```Shell/Bash
156+
kubectl cluster-info
157+
```
158+
159+
```Shell/Bash
160+
Example: https://api.xxx.kyma.ondemand.com
161+
```
162+
163+
And your `Cluster Domain` will be `xxx.kyma.ondemand.com`
164+
165+
166+
5. create the `destination` service instance with plan *lite* and the `xsuaa` service instance with plan
167+
*application* by running the below command.
168+
169+
```Shell/Bash
170+
kubectl apply -n sapfiori -f <Folder Path>/btp-hyperscaler-extension/kyma/createservice.yaml
171+
```
172+
> Replace your folder path in above command.
173+
> The create service file is represented as declarative YAML object which describes what you want to run inside your namespace. You can find the file at `/btp-hyperscaler-extension/master/kyma/createservice.yaml`.
174+
175+
6. Check that the status of the service instance in your cluster by using the following command:
176+
177+
```Shell/Bash
178+
kubectl get serviceinstances -n sapfiori
179+
```
180+
**This should return the status of created service instances.**
181+
182+
|NAME|CLASS|PLAN|STATUS|AGE|
183+
|-------|----|-------|--------|---------|
184+
|`destination-instance-fiori`| `ClusterServiceClass/destination`|`lite`|`Ready`|`##`|
185+
|`xsuaa-instance-fiori`| `ClusterServiceClass/xsuaa`|`application`|`Ready`|`##`|
186+
187+
>To know more about consuming services using SAP BTP service operator [Working with SAP BTP Service Operator](https://help.sap.com/viewer/09cc82baadc542a688176dce601398de/Cloud/en-US/0ccebd7cec24411dacd5ad17799534e0.html).
188+
189+
190+
### Build and deploy app into kyma Cluster
191+
192+
193+
To build and deploy the **`fioriapp`** sample application in your cluster, you have to create a pod, which encapsulates the container and ensures that a specified quorum of running instances is fulfilled. To do that, use the `deployment.yaml`.
194+
195+
1. Build the docker image of the **`fioriapp`**.
196+
197+
```Shell/Bash
198+
199+
cd `btp-hyperscaler-extension/basicfioriapp`
200+
201+
docker build . -t `<docker-username>/fioriapp` -f Dockerfile
202+
```
203+
>Replace `<docker-username>` with your username
204+
205+
2. Push the docker image of the `fioriapp` to your Container Image Library.
206+
207+
```Shell/Bash
208+
209+
docker push `<docker-username>/fioriapp`
210+
211+
```
212+
>Replace `<docker-username>` with your username
213+
214+
3. Update the docker image in the `<Folder path>/btp-hyperscaler-extension/kyma/deployment.yaml` file.
215+
216+
* Replace `<docker-username>` with your username
217+
218+
4. Execute the below command to deploy the application into kyma-cluster.
219+
220+
```Shell/Bash
221+
kubectl apply -n sapfiori -f <Folder path>/btp-hyperscaler-extension/kyma/deployment.yaml
222+
223+
```
224+
> Replace your folder path in above command.
225+
> The deployment file is represented as declarative YAML object which describes what you want to run inside your namespace. You can find the file at `/btp-hyperscaler-extension/master/kyma/deployment.yaml`.
226+
227+
5. Execute the following command to check the deployed application pod status
228+
229+
```Shell/Bash
230+
kubectl get pods -n sapfiori
231+
```
232+
233+
This should return the status of deployed application.
234+
235+
|NAME|READY|STATUS|RESTART|AGE|
236+
|-------|----|-------|--------|---------|
237+
|`fioriapp-##-##`| `2/2`|`Running`|`##`|`##`|
238+
239+
240+
### Apply resources to Kyma runtime
241+
242+
243+
kind Service is an abstract way to expose an application running on a set of Pods as a network service. Now we have the Deployment of **`fioriapp`**, let's deploy the Kubernetes Service to allow other Kubernetes resources to communicate with your microservice.
244+
Create `APIRule` to defines the API endpoint which exposes the application to the Internet.
245+
246+
1. Execute the below command to Create the Service and Expose the microservice.
247+
248+
Replace the `<Custom-Domain>` in `<Folder path>/btp-hyperscaler-extension/kyma/service.yaml` file.
249+
250+
```Shell/Bash
251+
kubectl apply -n sapfiori -f <Folder path>/btp-hyperscaler-extension/kyma/service.yaml
252+
```
253+
> Replace your folder path in above command.
254+
> The deployment file is represented as declarative YAML object which describes what you want to run inside your namespace. You can find the file at `/btp-hyperscaler-extension/master/kyma/service.yaml`.
255+
256+
257+
### Run the deployed application
258+
259+
260+
To access the API we can use the `APIRule` we created in the previous step.
261+
262+
1. Open the kyma-runtime console
263+
264+
2. From the menu, choose **Namespaces**
265+
266+
3. Choose the `sapfiori` Namespace.
267+
268+
4. From the menu, choose **Discovery and Network > `API Rules`**.
269+
270+
5. Choose the **Host** entry for the **`fioriapp`** `APIRule` to open the application in the browser. Application should return the list of business partners
271+
272+
`https://fioriapp.<cluster>.kyma.ondemand.com`
273+
274+
<!-- border -->![finaloutput](finaloutput.png)
275+
276+
**Congratulations!** You have successfully completed the tutorial.
277+
278+
279+
280+
---
33.1 KB
Loading
187 KB
Loading
41.4 KB
Loading
43.9 KB
Loading

0 commit comments

Comments
 (0)