How to: MultiContainer Pod, Init Container <a name="multicontainerpod"></a>
- Best Practice: 1 Container runs in 1 Pod normally, because the smallest element in K8s is Pod (Pod can be scaled up/down).
- Multicontainers run in the same Pod when containers are dependent of each other. 
- Multicontainers in one Pod have following features:
  - Multi containers that run on the same Pod run on the same Node.
  - Containers in the same Pod run/pause/deleted at the same time.
  - Containers in the same Pod communicate with each other on localhost, there is not any network isolation.
  - Containers in the same Pod use one volume commonly and they can reach same files in the volume.   

#### Init Containers
- Init containers are used for configuration of apps before running app container. 
- Init containers handle what it should run, then it closes successfully, after init containers close, app containers start. 
- Example below shows how to define init containers in one Pod. There are 2 containers: appcontainer and initcontainer. Initcontainer is polling the service (myservice). When it finds, it closes and app container starts.  

```yaml
apiVersion: v1
kind: Pod
metadata:
  name: initcontainerpod
spec:
  containers:
  - name: appcontainer            # after initcontainer closed successfully, appcontainer starts.
    image: busybox
    command: ['sh', '-c', 'echo The app is running! && sleep 3600']
  initContainers:
  - name: initcontainer
    image: busybox                # init container starts firstly and look up myservice is up or not in every 2 seconds, if there is myservice available, initcontainer closes. 
    command: ['sh', '-c', "until nslookup myservice; do echo waiting for myservice; sleep 2; done"]
```
   
- Please have a look Scenario (below link) to learn more information.

**Goto the Scenario:** [LAB: K8s Multicontainer - Sidecar - Emptydir Volume - Port-Forwarding](https://github.com/omerbsezer/Fast-Kubernetes/blob/main/K8s-Multicontainer-Sidecar.md)