Skip to Content

Set up a Kyma Cluster on the Command Line

You can 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.
You will learn
  • How to set up a Kyma cluster in a subaccount on SAP BTP, without using the SAP BTP 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.
Anna WengerAugust 11, 2022
Created by
MGruenhagel
August 11, 2022
Contributors
MGruenhagel

Prerequisites

  • Step 1
    1. Log in to your global account. We recommend using:

      Shell/Bash
      Copy
      btp login --sso
      

    2. Since you’ll be working in a subaccount, run:

      Shell/Bash
      Copy
      btp list accounts/subaccount
      
    3. Copy the ID of the subaccount in which you want to set up the Kyma cluster to your clipboard.

    4. Set the target to that subaccount with:

      Shell/Bash
      Copy
      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 any command.

  • Step 2

    To check if Kyma is already entitled to your subaccount, use the following command:

    Shell/Bash
    Copy
    btp list accounts/entitlements
    

    If 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:

    Shell/Bash
    Copy
    btp assign accounts/entitlement --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 --help to the end of complete or incomplete commands. For example, btp accounts/subaccounts --help can help you to find the correct command to get details about a subaccount.

  • Step 3

    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

    1. Create a .json file in a directory of your choice with the following content: {"name": "my-kyma-cluster", "region": "eu-west-2"}

    2. Run the following command to create the Kyma cluster:

      Shell/Bash
      Copy
      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 --subaccount <ID> ‒ once Kyma appears with status OK, you can continue.

  • Step 4

    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.

    1. To get your environment id, enter:

      Shell/Bash
      Copy
      btp list accounts/environment-instance
      

    2. Copy the environment ID of your new Kyma environment instance to your clipboard for use in the next command.

    3. To retrieve the KubeconfigURL, enter:

      Shell/Bash
      Copy
      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>

    4. Copy the KubeconfigURL.

    5. To download the kubeconfig.yaml file and save it to your user directory, enter:

    in PowerShell 5.1 (Windows):

    Shell/Bash
    Copy
    curl https://kyma-env-broker.cp.kyma.cloud.sap/kubeconfig/<EnvironmentID> -OutFile <file-path>\kubeconfig.yaml
    

    in PowerShell 7.x (Windows, Mac, Linux):

    Shell/Bash
    Copy
    curl https://kyma-env-broker.cp.kyma.cloud.sap/kubeconfig/<EnvironmentID> > <file-path>\kubeconfig.yaml
    

    in macOS:

    Shell/Bash
    Copy
    curl -o kubeconfig.yaml https://kyma-env-broker.cp.kyma.cloud.sap/kubeconfig/<ENVIRONMENT-ID>
    
  • Step 5

    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:

  • Step 6

    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:

    Shell/Bash
    Copy
    kubectl get namespaces
    

    You get a token which will also be valid for future sessions.

  • Step 7

    If you don’t want to do all the work in your Kyma cluster by yourself, you can assign roles to other users.

    See Assign Roles in the Kyma Environment for cockpit equivalent

Back to top