Pod adalah unit terkecil dalam Kubernetes yang dapat dibuat dan dikelola.
Pod adalah sekumpulan satu atau lebih kontainer yang berbagi penyimpanan, network, dan instruksi bagaimana kontainer akan berjalan.
The following is an example of a Pod which consists of a container running the image nginx:1.14.2.
kubectl apply -f - <<EOF
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
EOF
Sangat jarang pods untuk di buat secara langusng walaupun itu singleton pods. Ini karena pods bersifat efemer (dapat mati atau hilang kapan saja, misalnya saat node mati atau pod diganti).
Untuk memastikan aplikasi tetap berjalan stabil dan dapat diatur secara efisien, Kubernetes menyediakan workloads di atas pod, seperti :
Controllers for workload resources create Pods from a pod template and manage those Pods on your behalf.
PodTemplates are specifications for creating Pods, and are included in workload resources such as Deployments, Jobs, and DaemonSets.
Each controller for a workload resource uses the PodTemplate inside the workload object to make actual Pods. The PodTemplate is part of the desired state of whatever workload resource you used to run your app.
kubectl get pods
Untuk mengetahui lebih lengkap tentang pods pods yang berjalan. Seperti nodes berjalan pada node apa dan ip inernal pods.
kubectl get pods -o wide
Contoh:
```bash
ilyasa@k3s-master:~$ kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
created-the-wrong-way 1/1 Running 0 37m 10.42.3.4 k3s-worker-3 <none> <none>
my-pod 1/1 Running 0 6m 10.42.2.5 k3s-worker-2 <none> <none>
Untuk melihat lebih banyak informasi tentang pods:
kubectl describe pod my-pod
Contoh:
ilyasa@k3s-master:~$ kubectl describe pod my-pod
Name: my-pod
Namespace: default
Priority: 0
Service Account: default
Node: k3s-worker-2/192.168.100.32
Start Time: Mon, 26 Aug 2024 12:52:04 +0000
Labels: <none>
Annotations: <none>
Status: Running
IP: 10.42.2.5
IPs:
IP: 10.42.2.5
Containers:
my-container:
Container ID: containerd://651667235656a45fa3483e6a392646b23ebe655ca0573d05407ecc1e8d096f54
Image: nginx
Image ID: docker.io/library/nginx@sha256:447a8665cc1dab95b1ca778e162215839ccbb9189104c79d7ec3a81e14577add
Port: 80/TCP
Host Port: 0/TCP
State: Running
Started: Mon, 26 Aug 2024 12:53:01 +0000
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-8nlgl (ro)
Conditions:
Type Status
PodReadyToStartContainers True
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
kube-api-access-8nlgl:
Type: Projected (a volume that contains injected data from multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
ConfigMapOptional: <nil>
DownwardAPI: true
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 4m9s default-scheduler Successfully assigned default/my-pod to k3s-worker-2
Normal Pulling 4m9s kubelet Pulling image "nginx"
Normal Pulled 3m13s kubelet Successfully pulled image "nginx" in 55.673s (55.673s including waiting). Image size: 71026652 bytes.
Normal Created 3m13s kubelet Created container my-container
Normal Started 3m13s kubelet Started container my-container
kubectl delete pod my-pod
kubectl delete -f pod.yaml
Contoh:
ilyasa@k3s-master:~$ kubectl delete -f pod.yaml
pod "my-pod" deleted
kubectl edit pod my-pod