Pod Basics
(this post is part of the material I cover in my devops course)
pods are the basic computing unit of kubernetes.
Pods Facts
- A Pod (as in a pod of whales or pea pod) is a group of one or more containers
- Pod containers share storage and network resources
- ..so same IP address for all containers in the pod
- can share volumes, but each container have its own files
- All containers (and other shared resources) are run in the same node
- We'll get the details in a later post, but...ONLY TIGHTLY CPUPLED CONTAINERS SHOULD RUN IN THE SAME POD. (for example, a web-server and a database server are not good candodates to run together)
Using Pods
- You can run pods using the following ways:
- Using the kubectl run command. For example:
1 osboxes@osboxes:~$ kubectl run nginx --image=nginx 2 pod/nginx created 3 osboxes@osboxes:~$ kubectl get pods 4 NAME READY STATUS RESTARTS AGE 5 nginx 0/1 ContainerCreating 0 2s 6 osboxes@osboxes:~$ kubectl get pods 7 NAME READY STATUS RESTARTS AGE 8 nginx 1/1 Running 0 8s 9 osboxes@osboxes:~$
- Applying a yaml file that describes the pod. example:
1 $> 2 $> cat basic-pod.yaml 3 apiVersion: v1 4 kind: Pod 5 metadata: 6 name: nginx 7 labels: 8 color: blue 9 spec: 10 containers: 11 - name: nginx 12 image: nginx:1.14.2 13 ports: 14 - containerPort: 80 15 $> 16 $> kubectl apply -f basic-pod.yaml 17 pod/nginx created 18 $>
- Get information about your pod by using the
kubectl describe command.
For example:
1$> kubectl get pods
2NAME READY STATUS RESTARTS AGE
3nginx 1/1 Running 0 7m23s
4$>
5$> kubectl describe pods nginx
6Name: nginx
7Namespace: default
8Priority: 0
9Service Account: default
10Node: 5node-m05/192.168.67.6
11Start Time: Sun, 05 May 2024 03:48:47 -0400
12Labels: color=blue
13Annotations: <none>
14Status: Running
15IP: 10.244.4.2
16IPs:
17 IP: 10.244.4.2
18Containers:
19 nginx:
20 Container ID: docker://dde20fde26a948b9738c721743ac7cb79c3958d34ccab944c1ce224901cfff94
21 Image: nginx:1.14.2
22 Image ID: docker-pullable://nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
23 Port: 80/TCP
24 Host Port: 0/TCP
25 State: Running
26 Started: Sun, 05 May 2024 03:48:54 -0400
27 Ready: True
28 Restart Count: 0
29 Environment: <none>
30 Mounts:
31 /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-s7t8r (ro)
32Conditions:
33 Type Status
34 PodReadyToStartContainers True
35 Initialized True
36 Ready True
37 ContainersReady True
38 PodScheduled True
39Volumes:
40 kube-api-access-s7t8r:
41 Type: Projected (a volume that contains injected data from multiple sources)
42 TokenExpirationSeconds: 3607
43 ConfigMapName: kube-root-ca.crt
44 ConfigMapOptional: <nil>
45 DownwardAPI: true
46QoS Class: BestEffort
47Node-Selectors: <none>
48Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
49 node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
50Events:
51 Type Reason Age From Message
52 ---- ------ ---- ---- -------
53 Normal Scheduled 7m35s default-scheduler Successfully assigned default/nginx to 5node-m05
54 Normal Pulling 7m35s kubelet Pulling image "nginx:1.14.2"
55 Normal Pulled 7m29s kubelet Successfully pulled image "nginx:1.14.2" in 6.381s (6.381s including waiting). Image size: 109129446 bytes.
56 Normal Created 7m29s kubelet Created container nginx
57 Normal Started 7m28s kubelet Started container nginx
58$>