Description:
What is a pod?
- Kubernetes Object
- Smallest unit in Kubernetes that you can create or deploy.
- a set of containers with shared namespaces and shared filesystem volumes
- share network namespace, IP, network ports
- containers in a pod are in same namespace, communicated with eachother over
localhost
- Pod can be used:
- for single container:
- for mutiple containers that work together
- tightly couples and need to share resources
Using pods
Working with pods:
Static Pod:
- Managed by kubelet daemon on a specific node, without the kube-apiserver observing them → not managed by control plane
- bound to one kubelet in 1 node
- main use: components in Kubernetes Control Plane are static pods, they must be created before actual scheduling takes place
- defined in
/etc/kubernetes/manifests/
- the 4 components of control plane can be found here in control plane node
- each pod has yaml as same as API
- name format:
<static-pod-name>-<node-hostname>
- static pods are visible on kube-apiserver because kubelet creates a mirror pod on kube-apiserver for each static pod
- but can be deleted but kubelet will recreate immediately
Pod lifecycle:
| State | Des |
|---|
| Pending | being scheduled or images being pulled from registry |
| Running: | after successfull attached to a node |
| Failed | a container terminated with failture and wont be restarting |
| Succeeded | all containers finished running successfully and they wont be restarting |
| Unknown | state cant be retrieved |
| CrashLoopBackOff | one of the containers in the pod exited unexpectedly even after it was restarted |
API
- apiVersion: v1
- kind: Pod
- metadata
- spec: PodSpec
- status
PodSpec
- --- containers ---
- containers: []Container
- initContainers: []Container
- …
- --- volumes ---
- volumes:
- --- scheduling ---
- nodeSelector: map[string]string
- nodeName
- affinity
- tolerations: [] Toleration
- key
- operator
- value
- effect
- tolerationSecond
- schedulerName
- --- lifecycle ---
- restartPolicy
- …
- --- hostname and name resolution ---
- --- hosts namespaces ---
- --- service account ---
- --- security context ---
- --- alpha level ---
- hostUsers
- resources: ResourceRequiremets
- .
- limits: map[string]Quantity
- requests: map[string]Quantity
- name:
- --- image ---
- image:
- imagePullPolicy:
- --- entrypoint ---
- --- port ---
- --- env var ---
- --- volumes ---
- --- resources ---
- resources:
EphemeralContainer
LifecycleHandler
NodeAffinity
- preferredDuringSchedulingIgnoredDuringExecution ^9449a7
- preference
- matchExpressions
- matchFields
- weight
- requiredDuringSchedulingIgnoredDuringExecution ^f1dd99
- nodeSelectorTerms:
- matchExpressions
- matchFields
PodAffinity
- preferredDuringSchedulingIgnoredDuringExecution
- podAffinityTerm
- topologyKey
- labelSelector
- matchLabelKeys
- …
- weight
- requiredDuringSchedulingIgnoredDuringExecution
- topologyKey
- labelSelector
- …
PodAntiAffinity