본문 바로가기
DevOps/DockerKubernetes

Pod

by 계영수 2022. 9. 4.
728x90

As We discussed before with Kubernetes, our ultimate aim is to deploy our application in the form of containers on a set of machines that are configured as worker nodes in a cluster. However, kubernetes does not deploy containers directly on the worker nodes. The containers are encapsulated into a Kubernetes object known as pods.

A Pod is a single instance of an application. A pod is the smallest object that you can create in Kubernetes. Here we see the simplest of simplest cases where you have a single node, Kubernetes cluster with a single instance of your application running in a single Docker container encapsulated in a pod.

What if the number of users accessing your application increase and you need to scale your application, You need to add additional instances of your web application to share the load.

Now, where would you spin up additional instances? Do we bring up new container instance within the same Pod? NO we create new pod altogher with a new instance of the same application.

What if the user base futher increases and your current node has no sufficient capacity? Well, then you can always deploy additional pods on a new node in the cluster. You will have a new node added to the cluster to expand the cluster's physical capacity.

So, What I'm trying to illustrate in the slide is that pods usually have a 1 to 1 relationsip with containers running your application. To scale up you create new pods and to scale down you delete existing pod. You do not add additional containers to an existing pod to scale your application.

 

Also, if you're wondering how we implement all of this and how we achieve laod balancing between the containers, etc, we will get into all of that in a later lecture.

 

▶ Multi-Container PODs

A Single Pod can have multiple containers except for the fact that they are usually not multiple containers of the same kind. But sometimes you might have a scenario where you have a helper container that might be doing some kind of supporting task for our web application, such as processing a user, enter data, processing a file uploaded by the user, etc and You want these helper containers to live alongside your application container.

The two containers can also communicate with each other directly by referring to each other as local hosts since they share the same network space. Plus they can easily share the same storage space as well.

 

kubectl

Whtat this command really does is it deploys a Docker container by creating  a Pod. It first creates a pod automatically and deploys an instance of the nginx docker image

 

실습

vagrant@ubuntu-focal:~$ kubectl run nginx --image=nginx
pod/nginx created
vagrant@ubuntu-focal:~$
vagrant@ubuntu-focal:~$ kubectl get pods
NAME    READY   STATUS    RESTARTS   AGE
nginx   1/1     Running   0          33s
vagrant@ubuntu-focal:~$
vagrant@ubuntu-focal:~$ kubectl describe pod nginx
Name:             nginx
Namespace:        default
Priority:         0
Service Account:  default
Node:             minikube/192.168.49.2
Start Time:       Sun, 04 Sep 2022 06:27:23 +0000
Labels:           run=nginx
Annotations:      <none>
Status:           Running
IP:               172.17.0.3
IPs:
  IP:  172.17.0.3
Containers:
  nginx:
    Container ID:   docker://7bdc7d16df3b1dd5775b14dce5163a128e5431f5193875cc13cda68ceb2c9af9
    Image:          nginx
    Image ID:       docker-pullable://nginx@sha256:b95a99feebf7797479e0c5eb5ec0bdfa5d9f504bc94da550c2f58e839ea6914f
    Port:           <none>
    Host Port:      <none>
    State:          Running
      Started:      Sun, 04 Sep 2022 06:27:31 +0000
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-tqttk (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  kube-api-access-tqttk:
    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  2m15s  default-scheduler  Successfully assigned default/nginx to minikube
  Normal  Pulling    2m15s  kubelet            Pulling image "nginx"
  Normal  Pulled     2m7s   kubelet            Successfully pulled image "nginx" in 7.33124179s
  Normal  Created    2m7s   kubelet            Created container nginx
  Normal  Started    2m7s   kubelet            Started container nginx
vagrant@ubuntu-focal:~$
vagrant@ubuntu-focal:~$ kubectl get pods -o wide
NAME    READY   STATUS    RESTARTS   AGE     IP           NODE       NOMINATED NODE   READINESS GATES
nginx   1/1     Running   0          5m42s   172.17.0.3   minikube   <none>           <none>
728x90