Enable SAP BTP, Kyma Runtime Using the Command Line
Enabling SAP BTP, Kyma Runtime means creating a Kyma environment instance, i.e. a Kyma cluster. You can then use the Kyma cluster to build applications and extensions to SAP and third-party solutions, manage roles, have your Kubernetes objects backed up, and view metrics and logs.
Overview
You will learn
- How to set up a Kyma cluster in a subaccount on SAP BTP, without using the SAP BTP cockpit (see Enable SAP BTP, Kyma Runtime for the same procedure in the cockpit).
- That the creation of the Kyma cluster takes about 15 - 25 minutes. It happens after step 3 in this tutorial, so you might want to plan in a coffee break before continuing with step 4.
Prerequisites
Prerequisites
- You’ve installed the
btp CLIand familiarized yourself with it. See Get Started with btp CLI. - You’ve installed
kubectl CLI, including the pluginkubectl oidc-loginfor authentication. See Installing the Kubernetes Command Line Tool. If you’re on Windows, we recommendChocolateyto installkubectl. In addition, we recommendKrewto install and use thekubectl oidcplugin forKubernetes OpenID Connect (OIDC). - You have a global account and a subaccount on SAP BTP with admin rights. See Get an Account on SAP BTP to Try Out Free Tier Service Plans.
Steps
- Log in to your global account. We recommend using:
btp login --sso- Since you’ll be working in a subaccount, run:
btp list accounts/subaccountCopy the ID of the subaccount in which you want to set up the Kyma cluster to your clipboard.
Set the target to that subaccount with:
btp target --subaccount <subaccount ID from your clipboard>Once the target is set to the subaccount, you no longer need to specify the subaccount ID with every command.
To check if Kyma is already entitled to your subaccount, use the following command:
btp list accounts/entitlementsIf you don’t have a Kyma entitlement yet, run the following command – note that you need to have admin rights in the global account for managing entitlements, and that you do need the subaccount ID one last time in this case (luckily, it should still be in your clipboard):
btp assign accounts/entitlement --to-subaccount <subaccount ID from your clipboard> --for-service kymaruntime --plan free --amount 1 If you’re not working in a free tier subaccount, see Available Plans in the Kyma Environment.
You can append
--helpto the end of complete or incomplete commands. For example,btp accounts/subaccounts --helpcan help you to find the correct command to get details about a subaccount.
To create a Kyma environment instance (the Kyma cluster), you need to pass a .json file as a parameter that contains attributes of the Kyma cluster.
If you’re using a different plan, you might need a different region. See the Subaccount Regions section in Regions for the Kyma Environment
Create a .json file in a directory of your choice with the following content:
{"name": "my-kyma-cluster", "region": "eu-west-2"}Run the following command to create the Kyma cluster:
btp create accounts/environment-instance --display-name my-environment-instance --environment kyma --service kymaruntime --plan free --parameters <FULL-PATH-TO-JSON-FILE>A new Kubernetes cluster is set up, in which the Kyma runtime and all its components will run.
To continue with this tutorial, the Kyma cluster needs to be created, but this happens in the background and may take 15‒30 minutes. You can check the status with btp list accounts/environment-instance ‒ once Kyma appears with status OK, you can continue.
Once you’ve created the environment instance, you need to get its configuration file: the kubeconfig.yaml, because kubectl relies on the kubeconfig.yaml to configure access to the Kyma cluster.
To do so, retrieve the environment id and the KubeconfigURL from the newly created environment instance. Note that downloading the kubeconfig.yaml may succeed even if the cluster creation has not succeeded yet. But in this case, the content would be unusable. So make sure that the Kyma environment instance is in status OK after the previous step.
- To get your
environment id, enter:
btp list accounts/environment-instanceCopy the environment ID of your new Kyma environment instance to your clipboard for use in the next command.
To retrieve the
KubeconfigURL, enter:
btp get accounts/environment-instance <ENVIRONMENT-ID>Tip: If you prefer JSON output, use
btp --format json get accounts/environment-instance <ENVIRONMENT_ID> --subaccount <ID>
Copy the
KubeconfigURL.To download the kubeconfig.yaml file and save it to your user directory, enter:
in PowerShell 5.1 (Windows):
curl https://kyma-env-broker.cp.kyma.cloud.sap/kubeconfig/<EnvironmentID> -OutFile <file-path>\kubeconfig.yamlin PowerShell 7.x (Windows, Mac, Linux):
curl https://kyma-env-broker.cp.kyma.cloud.sap/kubeconfig/<EnvironmentID> > <file-path>\kubeconfig.yamlin macOS and Linux:
curl -o kubeconfig.yaml https://kyma-env-broker.cp.kyma.cloud.sap/kubeconfig/<ENVIRONMENT-ID>For your convenience, expose the kubeconfig as an environment variable or add the location of kubeconfig.yaml to your path in the system variables. The environment variable is session-based, whereas the path is saved permanently.
To only use a session-based environment variable, enter:
If you’ve created the cluster, you’re automatically assigned the cluster-admin role. This role gives you unrestricted access to configure your cluster. For example, you can assign roles to other users.
To check if you can access your cluster, run:
kubectl get namespacesYou get a token which will also be valid for future sessions.
To learn more about the Kyma environment and its functionality, see:
- SAP BTP, Kyma runtime
- SAP Help Portal - Kyma Environment
- kyma-project
- Kyma - YouTube
- Cloud Native for Beginners - YouTube
- Mission: Develop a Full-Stack Application in SAP BTP, Kyma Runtime
Resources
Discussion
Share feedback on this tutorial or join the conversation in SAP Community.