Usage Scenario
You have successfully created a Kyma runtime instance. Now, you want to interact with it and learn how to use the kubectl command line interface (CLI) to manage your resources. But first, you need to know how to set up the kubectl CLI to connect to your Kyma runtime, especially because Kyma runtime requires a special plugin of kubectl for the authentication process.
Task Flow
In this exercise, you will perform the following steps:
- Install the kubectl CLI.
- Install the kubelogin plugin.
- Configure the kubectl CLI to connect to your Kyma runtime instance.
- Interact with your Kyma runtime instance using kubectl.
Task 1: Install the Kubectl CLI
Prerequisites
You have successfully created a Kyma runtime instance in the SAP BTP subaccount.
Steps
Install the Kubectl CLI.
Follow the official documentation to install the kubectl CLI.
To verify that the kubectl CLI is installed correctly, run the following command in your terminal or command line:
Code Snippet1kubectl version --clientIf the installation was successful, you see the client and Kustomize versions as an output.
Install the Kubelogin Plugin.
Kyma runtime requires a special plugin called kubelogin for the kubectl CLI to connect to your Kyma runtime instance.
Follow the official documentation to install the kubelogin plugin.
To verify that the kubelogin plugin is installed correctly, execute the following command in your terminal or command line:
Code Snippet1kubectl version --clientIf the installation was successful, you see the client and kubelogin plugin versions as an output.
Task 2: Connect to Your Kyma Runtime Instance.
As already mentioned, kubectl relies on the kubeconfig file, which is typically located in the ~/.kube directory (macOS/Linux) or %USERPROFILE%\.kube (Windows).
Steps
Go to your SAP BTP subaccount overview page.
Select the link for the KubeconfigURL to download the kubeconfig.yaml file for your Kyma runtime instance.

In the terminal, export the location of your kubeconfig file as an environment variable.
For MacOS/Linux:
Code Snippet1export KUBECONFIG={KUBECONFIG_FILE_PATH}For Windows:
Code Snippet1$ENV:KUBECONFIG="{KUBECONFIG_FILE_PATH}"Note
The kubeconfig file contains credentials for accessing your Kyma runtime instance. Therefore, it is important to keep it secure.
To verify that the kubeconfig file is configured correctly, run the following command in your terminal or command line:
Code Snippet1kubectl cluster-infoIf successful, you see the following output:

Task 3: Access Resources in Your Kyma Runtime
It's now time to use a few kubectl commands to interact with your Kyma runtime instance. Remember that everything defined in Kubernetes can be accessed using the RESTful Kubernetes API.
Every kubectl command must specify the namespace and the object type. If no namespace is specified, kubectl assumes the default namespace. The object type is the name of the resource type, such as Pods or Deployments. The name of the object is the name of the resource, such as my-pod or my-deployment.
The kubectl syntax is as follows:
kubectl [command] [TYPE] [NAME] [flags]Steps
List Objects.
To list objects, you can use the get command. The get command lists one or more resources.
To list all Pods in all namespaces, use the following command:
Code Snippet1kubectl get all --all-namespacesTo list all Pods in a specific namespace, you can use the following command:
Code Snippet1kubectl get pods --namespace my-namespaceHint
The --namespace flag is optional. If you don't specify a namespace, the default namespace is used. However, you can also specify the namespace in the kubeconfig file or create different contexts for different namespaces, which you can then switch between or set your custom namespace as default. Read more about contexts in the official Kubernetes documentation.
Try out some other examples of the get command, which lists resources of a specified type in the default namespace:
Code Snippet1kubectl get podsCode Snippet1kubectl get servicesCode Snippet1kubectl get replicasetsCode Snippet1kubectl get deploymentsCode Snippet1kubectl get nodes
Create objects.
Create a new namespace:
Code Snippet1kubectl create namespace my-namespaceCreate a Pod in your newly created namespace:
Code Snippet12345678910cat <<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 EOFThe create command can also create a Kubernetes object from a YAML or JSON file. For example, you can define a Pod in a YAML file and create it using this command:
Code Snippet1kubectl create -f my-pod.yamlThe -f flag is short for --filename. It specifies the path to the YAML or JSON file that contains the object definition.
The third approach is to create objects from a URL. For example, you can use this command:
Code Snippet1kubectl create -f https://raw.githubusercontent.com/SAP-samples/kyma-runtime-learning-journey/main/unit_1/my-pod.yamlNote
If you run the create command twice with the same object definition, it throws an error. To avoid this, use the apply command instead.
Update objects.
To update objects, you can use the apply command. The apply command updates a Kubernetes object from a YAML or JSON file. For example, to update a Pod, you can use the following command:
Code Snippet1kubectl apply -f my-pod.yamlDuring an apply operation, the Kubernetes API server compares the object definition in the YAML or JSON file with the object's current state in the cluster. If there are any differences, the object is updated.
Describe objects.
To describe objects, you can use the describe command, which displays detailed information about a Kubernetes object.
For example, to describe a Pod, you can use the following command:
Code Snippet1kubectl describe pod my-pod
You can even export the output of the describe command to a YAML or JSON file. For example, to export the output of the describe command to a YAML file, you can use the following command:
Code Snippet1kubectl describe pod my-pod -o yaml > my-pod.yaml
Label objects.
To label objects, you can use the label command. The label command adds or updates labels on a Kubernetes object. For example, to add a label to a Pod, you can use the following command:
Code Snippet1kubectl label pod my-pod my-label=my-valueDelete objects.
To delete objects, you can use the delete command. For example, to delete a Pod, run:
Code Snippet1kubectl delete pod my-podTo delete the namespace you created, run:
Code Snippet1kubectl delete namespace my-namespace
Get cluster details.
To retrieve cluster information, use the cluster-info command. It displays information about the cluster.
Code Snippet1kubectl cluster-infoTo retrieve resource usage information for Nodes and Pods, use the top command.
Code Snippet1kubectl top nodesCode Snippet1kubectl top pods
To get a full list of all available commands, you can use the help command.
Code Snippet1kubectl help
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.