Kubernetes - Pod
Last Updated: 2023-08-27
apiVersion: v1
kind: Pod
Use controllers to manage pods, do not manage pods directly
Deployment
-> ReplicaSet
-> Pod
Containers in a Pod
In the simplest cases, each pod just have 1 container; in some cases each pod has more than 1 pods; with sidecars, each pod has at least 2 containers.
Order: first start spec.initContainers
then spec.containers
; no specific order when sttarting containers in spec.containers
.
Native Sidecar Containers since Kubernetes 1.28
Before 1.28:
- sidecar container is part of
spec.containers
- if app container starts faster than sidecar container, or shuts down after the sidecar container (i.e. sidecar container life-syscle shorter than app container), the app container cannot access the network.
- if app container exists but sidecar containers runs, the pod will be running indefinitely.
- init containers run before sidecar container, so cannot access the network.
After 1.28:
- sidecar container is part of
spec.initContainers
but withrestartPolicy: Always
- later containers in the list of
spec.initContainers
, and all normalspec.containers
will not start until the sidecar container is ready. - the pod will terminate even if the sidecar container is still running.
- later containers in the list of
Example:
apiVersion: v1
kind: Pod
spec:
initContainers:
- name: network-proxy
image: network-proxy:1.0
restartPolicy: Always
containers:
...