Multi-Container Pods Flashcards
What kind of patterns exist for multi-container pods in Kubernetes?
- Ambassador
- Sidecar
- Adapter
What are reasons for multi-container pods and what are consequences for the included containers?
- sometimes close-connection between two services needed
- both containers share lifecycle, network and storage of the pod
How do we create multi-container pods?
- in yaml add new container in spec section
What is a good example of a Sidecar patternß
- deploying a logging agent besides a webserver to collect logs and forward them to a central log server
- additional container with additional functionality
What is an example for the Adapter pattern?
- an adapter container that processes logs and standardizes the format
- before sending them forward to the centralized server
What is an example for the Ambassador pattern?
- i.e when you use three different databases for different environment (prod, dev, test)
- this connectivity needs to be configured in the application in dependence on the goal environment
- such logic may be outsourced to a separate container within the pod, so that the application can always refer to the database at localhost and your container will proxy the request to the right database
With what command can we see the logs of a running application/pod?
kubectl logs app-name -n namespace
What happens if any one container in one pod fail?
- the pod restarts
- all containers within a pod are expected to stay alive
What is initContainers used for?
- to run a task/process that will run only one time when the pod is first created or a process that waits for an external service or database to be up before the actual application starts
How do we configure a initContainer ?
in pod yaml:
spec: containers: - name: initContainers: - name: init-myservice image: busybox command: ['sh', '-c', 'git clone < some repo that will be used by the application;']
How does the initContainer work?
- when pod first created, the initContainer is run
- process in initContainer must run to completion before the real container hosting the application starts
Are multiple initContainers possible? What about sequence and failure?
Yes
- each initContainer is then run one at a time in a sequential order
- if any of the initContainer fails to complete, pod is restarted until it succeeds