How to: Pod: Creating, Yaml, LifeCycle <a name="pod"></a>
- Pod is the smallest unit that is created and managed in K8s.
- Pods may contain more than 1 container, but mostly pods contain only 1 container.
- Each pod has unique id (uid).
- Each pod has unique IP address.
- Containers in the same Pod run on the same Node (computer), and these containers can communicate with each other on the localhost. 
- Creation of the first pod, IMPERATIVE WAY (with command):
- Please have a look Scenario (**Creating Pod - Imperative way**, below link) to learn more information about the pod's kubectl commands.
    - how to create basic K8s pod using imperative commands,
    - how to get more information about pod (to solve troubleshooting),
    - how to run commands in pod,
    - how to delete pod. 

**Goto the Scenario:** [LAB: K8s Creating Pod - Imperative Way](https://github.com/omerbsezer/Fast-Kubernetes/blob/main/K8s-CreatingPod-Imperative.md) 

#### Pod: YAML File
- Imperative way could be difficult to store and manage process. Every time we have to enter commands. To prevent this, we can use YAML file to define pods and pods' feature. This way is called "Declarative Way".
- Declarative way (with file), Imperative way (with command)
- Sample Yaml File:

![image](https://user-images.githubusercontent.com/10358317/153674712-426a262d-d13e-489d-9c86-63ac22114d75.png)

- Please have a look Scenario (**Creating Pod - Declarative way**, below link) to learn more information.

**Goto the Scenario:** [LAB: K8s Creating Pod - Declarative Way (With File) - Environment Variable](https://github.com/omerbsezer/Fast-Kubernetes/blob/main/K8-CreatingPod-Declerative.md) 

#### Pod: Life Cycle
- **Pending:** API->etcd, pod created, pod id created, but not running on the node.
- **Creating:** Scheduler take pod from etcd, assing on node. Kubelet on the Node pull images from docker registry or repository.
- **ImagePullBackOff:** Kubelet can not pull image from registry. E.g. Image name is fault (typo error), Authorization Failure, Username/Pass error.
- **Running:** 
    - Container closes in 3 ways:
        1. App completes the mission and closes automatically without giving error,
        2. Use or System sends close signal and closes automatically without giving error,
        3. Giving error, collapsed and closes with giving error code. 
    - Restart Policies (it can defined in the pod definition): 
        1. Always: Default value, kubelet starts always when closing with or without error, 
        2. On-failure: It starts again when it gets only error, 
        3. Never: It never restarts in any case.
 - **Successed (completed)**: If the container closes successfully without error and restart policy is configured as on-failure/never, it converts to succeed.
 - **Failed**
 - **CrashLoopBackOff:** 
    - If restart policy is configured as always and container closes again and again, container restarts again and again (Restart waiting duration before restarting again: 10 sec -> 20 sec -> 40 sec -> .. -> 5mins), It runs every 5 mins if the pod is crashed.
    - If container runs more than 10 mins, status converted from 'CrashLoopBackOff' to 'Running'.