- Home
- >
- Software Development
- >
- Take the Kubernetes API for a Spin – InApps 2025
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 !
Key Summary
This article from InApps Technology, authored by Phu Nguyen, explores the Kubernetes API, the core of Kubernetes, a leading container orchestration platform. It highlights Kubernetes’ API-first approach, treating all operations (e.g., creating/deleting pods, services) as REST API calls. The article provides a hands-on tutorial for setting up a Kubernetes cluster, configuring a proxy, and interacting with the API using tools like cURL, jq, and Postman, demonstrating how to create and manage pods and services.
- Context:
- Kubernetes Overview: An open-source platform from Google, Kubernetes excels in distributed computing and cluster management, with an extensible API-first architecture.
- Kubernetes API: The API server in the control plane handles REST operations, managing the cluster’s shared state and enabling interaction with components like pods, services, and replica sets.
- Tutorial Goal: Guide developers through setting up a cluster, accessing the API via a proxy, and performing operations like creating a NGINX pod and service.
- Kubernetes Architecture:
- API Server: Processes REST operations, handling authentication, authorization, and admission control. Accessible via port 443 (TLS) with a self-signed certificate stored at $USER/.kube/config.
- Kubectl: A command-line client for the Kubernetes API, simplifying interactions.
- Client Libraries: Official Go client and third-party libraries for Node.js, PHP, Python, and Java available on GitHub.
- Tutorial: Interacting with the Kubernetes API:
- Set Up a Cluster:
- Options:
- Minikube: Simplest for local setup on Mac/Windows (follow GitHub instructions).
- Vagrant Multi-Node: Simulates a real cluster using CoreOS Kubernetes repo.
- Google Container Engine (GKE): Fully managed cluster via Google Cloud Platform and Cloud SDK.
- Verification:
- Run kubectl cluster-info and kubectl get componentstatuses to confirm the cluster is operational.
- Options:
- Configure the Proxy:
- Run kubectl proxy to forward requests from localhost:8000 to the API server.
- Access the API:
- Visit http://localhost:8000/swagger-ui/ to explore endpoints (may not work with Minikube).
- Use cURL to query nodes:
text
CollapseWrap
Copy - curl http://localhost:8000/api/v1/nodes
- Install jq for readable JSON output:
text
CollapseWrap
Copy - curl http://localhost:8000/api/v1/nodes | jq
- Alternatively, use Postman for API exploration.
- Create a Pod and Service:
- Create NGINX Pod:
- Define a pod configuration and use cURL to create it:
text
CollapseWrap
Copy - curl –data @nginx-pod.json http://localhost:8000/api/v1/namespaces/default/pods
- The pod is scheduled, and the NGINX image is downloaded.
- Define a pod configuration and use cURL to create it:
- Create Service:
- Define a service to expose the NGINX pod and create it via cURL:
text
CollapseWrap
Copy - curl –data @nginx-service.json http://localhost:8000/api/v1/namespaces/default/services
- Define a service to expose the NGINX pod and create it via cURL:
- Verify:
- Check pods and services with:
text
CollapseWrap
Copy
- Check pods and services with:
- Create NGINX Pod:
- Set Up a Cluster:
kubectl get pods
- kubectl get services
- Access Service: Use the proxy to access the NGINX service.
- Cleanup: Delete the pod and service using kubectl delete.
- Resources: The tutorial script is available on GitHub.
- Key Insights:
- Extensibility: Kubernetes’ API-first design makes it programmable, allowing all kubectl and dashboard tasks to be executed via API calls.
- Ease of Use: Tools like kubectl proxy, cURL, and Postman simplify API interaction.
- Community Support: Multiple client libraries enhance accessibility for developers across languages.
- InApps Insight:
- InApps Technology, ranked 1st in Vietnam and 5th in Southeast Asia for app and software development, specializes in Kubernetes-based solutions for containerized applications.
- Leverages React Native, ReactJS, Node.js, Vue.js, Microsoft’s Power Platform, Azure, Power Fx (low-code), Azure Durable Functions, and GraphQL APIs (e.g., Apollo) to build scalable orchestration systems.
- Offers outsourcing services for startups and enterprises, delivering Kubernetes-driven solutions at 30% of local vendor costs, supported by Vietnam’s 430,000 software developers and 1.03 million ICT professionals.
- Note: InApps is a subsidiary of Insight Partners, an investor in Postman, mentioned in the article.
- Call to Action:
- Contact InApps Technology at www.inapps.net or sales@inapps.net to develop Kubernetes-based applications or explore API-driven orchestration solutions.
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.
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:
- 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.
- 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.
- 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:
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.
kubectl proxy —port=8000 |
Through this proxy session, any request sent to localhost:8000 will be forwarded to the Kubernetes API server.
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.
Expanding the /api/v1 section will show us all the available endpoints.
Let’s now use cURL to play with the API.
curl http://localhost:8000/api |
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.
The equivalent curl command to get all the nodes is pretty straight forward. Jq is used for making the output prettier and human readable.
curl –s http://localhost:8000/api/v1/nodes | jq ‘.items[] .metadata.labels’ |
If you like, you can also use Postman to explore Kubernetes API.
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
cat > nginx–pod.json <<EOF { “kind”: “Pod”, “apiVersion”: “v1”, “metadata”:{ “name”: “nginx”, “namespace”: “default”, “labels”: { “name”: “nginx” } }, “spec”: { “containers”: [{ “name”: “nginx”, “image”: “nginx”, “ports”: [{“containerPort”: 80}], “resources”: { “limits”: { “memory”: “128Mi”, “cpu”: “500m” } } }] } } EOF |
We will then create a service definition to expose the NGINX pod that was just scheduled.
cat > nginx–service.json <<EOF { “kind”: “Service”, “apiVersion”: “v1”, “metadata”: { “name”: “nginx-service”, “namespace”: “default”, “labels”: {“name”: “nginx”} }, “spec”: { “ports”: [{“port”: 80}], “selector”: {“name”: “nginx”} } } EOF |
The next step is to create the pod object by invoking the following command.
curl –s http://localhost:8000/api/v1/namespaces/default/pods –XPOST –H ‘Content-Type: application/json’ –d@nginx–pod.json | jq ‘.status’ |
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.
<br />
-XPOST -H ‘Content-Type: application/json’
<br />
<br />
-d@nginx-service.json
<br />
<br />
| jq ‘.spec.clusterIP’
curl –s http://localhost:8000/api/v1/namespaces/default/services –XPOST –H ‘Content-Type: application/json’ –d@nginx–service.json | jq ‘.spec.clusterIP’ |
Let’s make sure that both the objects are created. We will use kubectl to list the pods and services.
Finally, let’s access the Nginx service through the proxy.
curl http://localhost:8000/v1/proxy/namespaces/default/services/nginx-service/ |
Time to clean up by deleting the pod and the service that we created.
curl http://localhost:8000/api/v1/namespaces/default/services/nginx-service -XDELETE |
curl http://localhost:8000/api/v1/namespaces/default/pods/nginx -XDELETE |
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
Let’s create the next big thing together!
Coming together is a beginning. Keeping together is progress. Working together is success.