Interacting with the Kubernetes API Using Kubectl

Objective

After completing this lesson, you will be able to install, configure, and use kubectl to interact with the Kubernetes API

Interacting with the Kubernetes API via Kubectl

Usage Scenario

Having just discovered which kind of objects you can create in Kubernetes, let's find out how to interact with the Kubernetes API to create, update, and delete these objects. For this, you will use the kubectl command-line tool, which is the primary way to interact with the Kubernetes API.

What is Kubectl?

To interact with the Kubernetes API, you need a client. The Kubernetes API is a REST API, which means that you can interact with it using any HTTP client. Since, you typically also have to deal with authentication and authorization, it is much easier to use a dedicated client like kubectl.

Kubernetes architecture showing the Control Plane (master node) containing a kube-apiserver which connects to nodes 1 to node n.,

Configuring Kubectl

To use kubectl, you must install it on your local machine and configure it to point to a specific Kubernetes cluster. First, you need a kubeconfig file. This file includes important information about your cluster, such as the API server URL, the authentication method, and the certificate authority. The kubeconfig file is usually stored in the home directory of your user account. For example, on Linux, the kubeconfig file is located at ~/.kube/config, and on Windows, you can find it at %USERPROFILE%\.kube\config.

In one of the next lessons, you'll learn how to download a kubeconfig file and configure kubectl for interacting with your Kubernetes cluster. For Kyma, along with kubectl, the kubelogin plugin is also required.

Once the kubeconfig file is properly configured, kubectl will use the information from that file to interact with the Kubernetes API when you issue commands. You can also configure kubectl by exporting the kubeconfig file in the terminal or use the KUBECONFIG environment variable to specify the location of the kubeconfig file.

Hint

This approach is similar to using the CF LOGIN command in Cloud Foundry runtime.

Further Reading about Interacting with the Kubernetes API via Kubectl

Find further information about interacting with the Kubernetes API via kubectl here: