Setting and Configuring Kubectl for Kyma

Objective

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
      Copy code
      Switch to dark mode
      1
      kubectl version --client

      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
      Copy code
      Switch to dark mode
      1
      kubectl krew install oidc-login

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

      Code Snippet
      Copy code
      Switch to dark mode
      12345
      # Homebrew (macOS and Linux) brew install int128/kubelogin/kubelogin # Chocolatey (Windows) choco install kubelogin
  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
      Copy code
      Switch to dark mode
      1
      mkdir ~/.kube

      On Windows:

      Code Snippet
      Copy code
      Switch to dark mode
      1
      mkdir %USERPROFILE%\.kube

    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
      Copy code
      Switch to dark mode
      1
      kubectl cluster-info
    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
      Copy code
      Switch to dark mode
      1
      kubectl get all
    2. Get a list of your nodes in your SAP BTP, Kyma runtime instance:

      Code Snippet
      Copy code
      Switch to dark mode
      1
      kubectl get nodes
    3. Get a list of your pods in your SAP BTP, Kyma runtime instance:

      Code Snippet
      Copy code
      Switch to dark mode
      1
      kubectl get pods
    4. Get a list of your deployments in your SAP BTP, Kyma runtime instance:

      Code Snippet
      Copy code
      Switch to dark mode
      1
      kubectl get deployments
    5. Create a new namespace in your SAP BTP, Kyma runtime instance:

      Code Snippet
      Copy code
      Switch to dark mode
      1
      kubectl create namespace my-namespace
    6. Get a list of all namespaces in your SAP BTP, Kyma runtime instance:

      Code Snippet
      Copy code
      Switch to dark mode
      1
      kubectl get namespaces
    7. Delete the namespace you just created:

      Code Snippet
      Copy code
      Switch to dark mode
      1
      kubectl delete namespace my-namespace

      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