Setting and Configuring Kubectl for Kyma

Objective

After completing this lesson, you will be able to set up and configure kubectl for Kyma

Setting and Configuring Kubectl for Kyma

Accessing Your Kyma Runtime Instance Using Kubectl

You have successfully created a Kyma runtime instance. Now, you want to interact with your Kyma runtime instance and learn how to use the kubectl CLI to manage your resources. But first, you need to know how to set up the kubectl command line interface (CLI) to connect to your Kyma runtime instance, especially because Kyma runtime requires a special plugin of kubectl for the authentication process.

Set up and configure kubectl for Kyma

In this exercise, you will perform the following steps:

  1. Install the kubectl CLI.
  2. Install the kubelogin plugin.
  3. Configure the kubectl CLI to connect to your Kyma runtime instance.
  4. Interact with your Kyma runtime instance using kubectl.

Prerequisites

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

Task 1: Install the Kubectl CLI

Steps

  1. Install the Kubectl CLI.

    1. Follow the official documentation to install the kubectl CLI.

    2. To verify that the kubectl CLI is installed correctly, execute the following command in your terminal or command line:

      Code Snippet
      1
      kubectl version --client

      If the installation was successful, you should see the client and Kustomize versions as an output.

  2. Install the Kubelogin Plugin.

    Kyma runtime requires a special plugin called kubelogin for the kubectl CLI to connect to your Kyma runtime instance.

    1. Follow the official documentation to install the kubelogin plugin.

    2. To verify that the kubelogin plugin is installed correctly, execute the following command in your terminal or command line:

      Code Snippet
      1
      kubectl version --client

      If the installation was successful, you should see the client and kubelogin plugin versions as an output.

  3. Connect to your Kyma runtime instance.

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

    1. Go to your SAP BTP subaccount overview page.

    2. Select the link for the KubeconfigURL to download the kubeconfig.yaml file for your Kyma runtime instance.

      KubeconfigURL
    3. In the terminal, export the location of your kubeconfig file as an environment variable.

      For MacOS/Linux:

      Code Snippet
      1
      export KUBECONFIG={KUBECONFIG_FILE_PATH}

      For Windows:

      Code Snippet
      1
      $ENV:KUBECONFIG="{KUBECONFIG_FILE_PATH}"

      Note

      The kubeconfig file contains the credentials for accessing your Kyma runtime instance. Therefore, it is important to keep it secure.

    4. To verify that the kubeconfig file is configured correctly, execute the following command in your terminal or command line:

      Code Snippet
      1
      kubectl cluster-info
    5. If the configuration was successful, you should see the following output:

      Terminal output showing the result of the command kubectl cluster-info. It displays the Kubernetes control plane and CoreDNS running at specific URLs, with a suggestion to use kubectl cluster-info dump for debugging.
  4. Interact with your Kyma runtime instance.

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

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

      Code Snippet
      1
      kubectl get all --all-namespaces
    2. Get a list of your nodes in your Kyma runtime instance:

      Code Snippet
      1
      kubectl get nodes
    3. Get a list of your Pods in your Kyma runtime instance:

      Code Snippet
      1
      kubectl get pods --all-namespaces
    4. Get a list of your Deployments in the namespace kyma-system:

      Code Snippet
      1
      kubectl get deployments -n kyma-system
    5. Create a new namespace:

      Code Snippet
      1
      kubectl create namespace my-namespace
    6. Create a Pod in your newly created namespace:

      Code Snippet
      12345678910
      cat <<EOF | kubectl -n my-namespace apply -f - apiVersion: v1 kind: Pod metadata: name: my-pod spec: containers: - name: my-container image: nginx:1.21.3 EOF
    7. Get a list of all namespaces in your Kyma runtime instance:

      Code Snippet
      1
      kubectl get namespaces
    8. Delete the namespace you created:

      Code Snippet
      1
      kubectl delete namespace my-namespace

      Result

      You have successfully installed the kubectl CLI and configured it to connect to your Kyma runtime instance. You can use the basic kubectl commands to interact with it.

Log in to track your progress & complete quizzes