Pods
Pods are a core component and the heart 💖 of Kubernetes deployments
Pods are the fundamental building blocks in Kubernetes, representing a single instance of a running process in a cluster. They encapsulate one or more containers, along with shared resources such as network and storage volumes.
Pods provide a cohesive environment for running containers that need to work together and share resources. They enable the deployment of tightly coupled application components within a Kubernetes cluster. For example, a pod can consist of multiple containers that communicate with each other using local network interfaces, allowing them to collaborate seamlessly.
Kubernetes schedules and manages pods as the unit of deployment. It ensures that the desired number of pods are running and handles scaling, self-healing, and load balancing. Pods can be replicated and distributed across multiple nodes in a cluster to ensure high availability and fault tolerance.
Additionally, pods have their own IP address and can be accessed directly within the cluster, which facilitates easy communication and service discovery between different pods and services. They can also share storage volumes, allowing data to be shared and persisted across multiple containers within a pod.
Overall, pods play a crucial role in Kubernetes deployments, serving as the basic unit of deployment, scaling, and management, and enabling the efficient orchestration of containerized applications within a cluster.
- kubectl
- curl
- Httpie
kubectl get pods --server=https://api.k1s.me/kubernetes
curl https://api.k1s.me/kubernetes/api/v1/pods
https api.k1s.me/kubernetes/api/v1/pods
- JavaScript
- Python
- Java
// index.js
const https = require('https');
const options = {
hostname: 'api.k1s.me',
port: 443,
path: '/kubernetes/api/v1/pods',
method: 'GET'
};
const req = https.request(options, res => {
console.log(`statusCode: ${res.statusCode}`);
res.on('data', d => {
process.stdout.write(d);
});
});
req.on('error', error => {
console.error(error);
});
req.end();
Execute code above assuming the file is named index.js
?
- Install Node.js from https://nodejs.org/en/download/
- Open a terminal and run
node index.js
- The output should be similar to the following:
statusCode: 200
# k1s-pods.py
import requests
url = "https://api.k1s.me/kubernetes/api/v1/pods"
payload={}
headers = {}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
Execute code above assuming the file is named k1s-pods.py
?
- Install Python from https://www.python.org/downloads/
- Open a terminal and run
python k1s-pods.py
- The output should be similar to the following:
statusCode: 200
// K1sPods.java
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import java.io.IOException;
public class K1sPods {
public static void main(String[] args) throws IOException {
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
Request request = new Request.Builder()
.url("https://api.k1s.me/kubernetes/api/v1/pods")
.method("GET", null)
.build();
Response response = client.newCall(request).execute();
}
}
Execute this code above assuming the file is named K1sPods.java
?
- Install Java from https://www.oracle.com/java/technologies/javase-downloads.html
- Download the OkHttp library from https://square.github.io/okhttp/ or mavencentral
- Open a terminal and run
javac K1sPods.java
- Run
java K1sPods
- The output should be similar to the following:
statusCode: 200
$ curl -k https://repo1.maven.org/maven2/com/squareup/okhttp3/okhttp/4.11.0/okhttp-4.11.0.jar -o okhttp-4.11.0.jar
$ javac -cp okhttp-4.11.0.jar:. K1sPods.java
$ java -cp okhttp-4.11.0.jar:. K1sPods
References: