Setting and Configuring Kubectl for Kyma

Objectives

After completing this lesson, you will be able to:

  • Set up and configure kubectl for Kyma

Setup and Configure Kubectl for Kyma

Business Scenario

You have successfully created a SAP BTP, Kyma runtime instance and have access to the Kyma Dashboard. You now want to interact with your SAP BTP, Kyma runtime instance and learn how to use the Kyma Dashboard and the kubectl CLI to manage your resources. But first, you need to learn how to set up the kubectl CLI to connect to your SAP BTP, Kyma runtime instance. Especially because the SAP BTP, Kyma runtime requires a special plugin of kubectl for the authentication process.

Exercise Options

You can perform this exercise in two ways:

  1. Platform Simulation – follow the step-by-step instructions within the simulation.
  2. Live Environment - by using the instructions provided below, you can perform the steps in the SAP BTP Free Tier account.
Note

We are strongly recommending first performing the steps in the Live Environment.

Platform Simulation

Choose the Start Exercise button below to open a simulation of the platform. Then follow the step-by-step instructions to setup and configure kubectl for Kyma.

Live Environment

In this exercise, you will perform the following steps:

  1. Install the kubectl CLI.
  2. Install an additional plugin for kubectl to connect to Kyma.
  3. Configure the kubectl CLI to connect to your SAP BTP, Kyma runtime instance.
  4. Use the kubectl CLI to connect to your SAP BTP, Kyma runtime instance.

Prerequisites

You have successfully created a SAP BTP, Kyma runtime instance in the SAP BTP subaccount.

Task 1: Install the kubectl CLI

Steps

  1. Install the kubectl CLI

    The official documentation of Kubernetes provides a detailed description of how to install the kubectl CLI. Please follow the instructions provided in the official documentation to install the kubectl CLI for your operating system.

    1. Follow the instructions to install the kubectl CLI for your operating system from the official documentation.

    2. Verify that the kubectl CLI is installed correctly by executing the following command in your terminal or command line:

      Code snippet
      kubectl version --client
      Expand

      If the installation was successful, you should see the version of the kubectl CLI as output.

  2. Install an additional plugin for kubectl to connect to Kyma.

    The SAP BTP, Kyma runtime requires a special plugin for the kubectl CLI to connect to the SAP BTP, Kyma runtime. This plugin is called kubelogin.

    1. The kubelogin plugin can be installed via kubectl's plugin manager krew. To install krew on your local machine, please follow the instructions provided in the official documentation here.

    2. To install the kubelogin plugin, execute the following command in your terminal or command line:

      Code snippet
      kubectl krew install oidc-login
      Expand

      Alternatively, you can also install it via choco (Windows) or brew (macOS/Linux):

      Code snippet
      # Homebrew (macOS and Linux)
      brew install int128/kubelogin/kubelogin
      
      # Chocolatey (Windows)
      choco install kubelogin
      Expand
  3. Configure the kubectl CLI to connect to your SAP BTP, Kyma runtime instance.

    As already mentioned, the kubectl is relying on the kubeconfig file, which is typically located in the ~/.kubedirectory (macOS/Linux) or %USERPROFILE%\.kube (Windows).

    1. Create the .kube directory if it does not exist yet:

      On macOS/Linux:

      Code snippet
      mkdir ~/.kube
      Expand

      On Windows:

      Code snippet
      mkdir %USERPROFILE%\.kube
      Expand

    2. Go to your SAP BTP subaccount overview page and select the link for the KubeconfigURL to download the kubeconfig file for your SAP BTP, Kyma runtime instance.

      This will download a kubeconfig.yaml file.

    3. Move the kubeconfig.yaml file to the .kube directory and rename it to config.

    4. After doing so, check that your .kube directory contains the config file.

      Note

      The kubeconfig file contains the credentials for your SAP BTP, Kyma runtime instance. Therefore, it is important to keep it secure. For this reason, we do not show the content of the file in this exercise. And typically, all .dotfolders are hidden in your file system by default. You can change this behavior in your operating system settings.

    5. Verify that the kubeconfig file is configured correctly by executing the following command in your terminal or command line:

      Code snippet
      kubectl cluster-info
      Expand
    6. If the configuration was successful, you should see the following output:

  4. Use the kubectl CLI to connect to your SAP BTP, Kyma runtime instance.

    It's now time to use some of the kubectl commands to interact with your SAP BTP, Kyma runtime instance.

    1. Execute the following command to get a list of all available resources in your SAP BTP, Kyma runtime instance:

      Code snippet
      kubectl get all
      Expand
    2. Get a list of your nodes in your SAP BTP, Kyma runtime instance:

      Code snippet
      kubectl get nodes
      Expand
    3. Get a list of your pods in your SAP BTP, Kyma runtime instance:

      Code snippet
      kubectl get pods
      Expand
    4. Get a list of your deployments in your SAP BTP, Kyma runtime instance:

      Code snippet
      kubectl get deployments
      Expand
    5. Create a new namespace in your SAP BTP, Kyma runtime instance:

      Code snippet
      kubectl create namespace my-namespace
      Expand
    6. Get a list of all namespaces in your SAP BTP, Kyma runtime instance:

      Code snippet
      kubectl get namespaces
      Expand
    7. Delete the namespace you just created:

      Code snippet
      kubectl delete namespace my-namespace
      Expand

      Result

      You have successfully installed the kubectl CLI and configured it to connect to your SAP BTP, Kyma runtime instance. You have also learned how to use the kubectl CLI to interact with your SAP BTP, Kyma runtime instance.

Log in to track your progress & complete quizzes