Take the Kubernetes API for a Spin – InApps is an article under the topic Software Development Many of you are most interested in today !! Today, let’s InApps.net learn Take the Kubernetes API for a Spin – InApps in today’s post !

Read more about Take the Kubernetes API for a Spin – InApps at Wikipedia



You can find content about Take the Kubernetes API for a Spin – InApps from the Wikipedia website

For anyone who is fascinated by distributed computing, Kubernetes provides an ultimate playground. It’s one of best implementations of cluster management software of our times. Google must be appreciated for not only open sourcing Kubernetes, but also simplifying it, and making it accessible to the developers.

At the heart of Kubernetes is an application programming interface (API). In fact, everything and anything in the platform is treated as an API object. Tasks such as the creation and deletion of pods, services, and replica sets are all translated into appropriate REST API calls.

This article discovers the hidden gems of Kubernetes API along with a detailed walkthrough. To get more from this tutorial, you are advised to spin up a cluster for yourself.

Architecture & Background

One of the key components of Kubernetes control plane is the API server. It is responsible for dealing with the REST operations while providing the front-end to the cluster’s shared state through which all other components interact. Every operation that involves changing the state of a Kubernetes objects such as a Pod goes through the API server.

Kubectl, the command line interface to Kubernetes, is a simple yet powerful client of this API.

The lesser known fact is that there are multiple client libraries available for the Kubernetes API. While the Go client is the official one, there are 3rd party clients for Node.js, PHP, Python, and Java available on Github.

Read More:   What’s Next for CNCF in 2017 – InApps 2022

Kubernetes-Architecture

In a typical Kubernetes cluster, the API is exposed on port 443, which can be accessed through a TLS connection. The self-signed certificate, which is generated during the cluster creation or configuration, is available at $USER/.kube/config on the user’s machine. But the access to the API server can be simplified through the proxy, which we will configure in the tutorial.

The API server performs authentication, authorization, and admission control of clients. Refer to Kubernetes API documentation for more details.

Setting up the Cluster

There are three ways to get the Kubernetes cluster up and running:

  1. Minikube – This is the simplest way to get a Kubernetes cluster on your Mac or Windows machine. Follow the instructions mentioned on the GitHub page.
  2. Vagrant Multi-Node – If you want to go beyond the basics to get a sense of the real Kubernetes cluster, clone the CoreOS Kubernetes repo and fire the vagrant up The folks at CoreOS does a great job of maintaining the repo along with the step-by-step guide.
  3. Google Container Engine – This is by far the simplest way to gain access to a full-blown Kubernetes cluster. Sign up with Google Cloud Platform, download the Cloud SDK and spin up the mighty powerful GKE cluster.

The entire script for this tutorial is also available on GitHub.

Verifying the Installation

Once you have access to a running cluster, verify that everything is intact by running the following commands:

Kubernetes-cluster-info

Kubernetes-component-status

If you see a similar output, the Kubernetes cluster is in perfect shape. We are all set to explore the API.

Configuring the Proxy

The easiest way to access Kubernetes API is to configure a proxy. Luckily, kubectl comes with an option to configure it.

Open a new terminal window and run the following command to create the proxy.

Kubernetes-proxy

Through this proxy session, any request sent to localhost:8000 will be forwarded to the Kubernetes API server.

Read More:   Are You Cut Out for That Dev Life? – InApps 2022

Now that we are all set, let’s go ahead and make our first API call. But before that, let’s explore the Swagger UI.

Accessing and Invoking the API

Visit http://localhost:8000/swagger-ui/ from the browser to access Swagger. This may not be available if you are using Minikube.

Kubernetes-Swagger

Expanding the /api/v1 section will show us all the available endpoints.

Kubernetes-Swagger-Endpoints

Let’s now use cURL to play with the API.

Kubernetes-curl-nodes

Let’s have some more fun playing with the API. To make things readable, install jq, the versatile JSON command line parser.

One of the most commonly used commands is kubectl get nodes, which returns the following output.

Kubernetes-get-nodes

The equivalent curl command to get all the nodes is pretty straight forward. Jq is used for making the output prettier and human readable.

Kubernetes-curl-nodes

If you like, you can also use Postman to explore Kubernetes API.

Kubernetes-Postman

Let’s take this to the next level by creating a pod through the API.

Creating a Pod and Service from the API

First, let’s define a pod. The below command will create a simple NGINX pod.

We will then create a service definition to expose the NGINX pod that was just scheduled.

The next step is to create the pod object by invoking the following command.

Kubernetes-curl-create-pod

We filtered the cURL output only to show the status. In a few seconds, the NGINX image will be downloaded and scheduled in one of the nodes.

With the NGINX pod in place, let’s also create a service. This process is very similar to the creation of the pod.

Kubernetes-curl-create-svc

Let’s make sure that both the objects are created. We will use kubectl to list the pods and services.

Kubernetes-get-pods

Kubernetes-get-svc

Finally, let’s access the Nginx service through the proxy.

Kubernetes-Proxy-Nginx

Time to clean up by deleting the pod and the service that we created.

Summary

Kubernetes is one of the most extensible container orchestration engines available today. Powered by Google’s decades of experience in managing massive infrastructure, it brings web-scale computing to masses. The API-first approach makes Kubernetes programmable and extensible. As we have seen in the walkthrough, it is easy to get started with the API. Any task that can be performed through the dashboard or kubectl client is exposed as an API.

InApps is a wholly owned subsidiary of Insight Partners, an investor in the following companies mentioned in this article: Postman.

Feature image via Pixabay.



Source: InApps.net

Rate this post
As a Senior Tech Enthusiast, I bring a decade of experience to the realm of tech writing, blending deep industry knowledge with a passion for storytelling. With expertise in software development to emerging tech trends like AI and IoT—my articles not only inform but also inspire. My journey in tech writing has been marked by a commitment to accuracy, clarity, and engaging storytelling, making me a trusted voice in the tech community.

Let’s create the next big thing together!

Coming together is a beginning. Keeping together is progress. Working together is success.

Let’s talk

Get a custom Proposal

Please fill in your information and your need to get a suitable solution.

    You need to enter your email to download

      Success. Downloading...