Pods
Last updated
Last updated
Pods are Kubernetes Objects that are the basic unit for running our containers inside our Kubernetes cluster. In fact, Pods are the smallest object of the Kubernetes Model.
Kubernetes uses pods to run an instance of our application and a single pod represents a single instance of that application. We can scale out our application horizontally by adding more Pod replicas.
Pods can contain a single or multiple containers as a group, that share the same resources within that Pod (storage, network resources, namespaces).
Pods are ephemeral resources, meaning that Pods can be terminated at any point and then restarted on another node within our Kubernetes cluster.
Running a single container in a Pod is a common use case. Here, the Pod acts as a wrapper around the single container and Kubernetes manages the Pods rather than the containers directly.
We can also run multiple containers in a Pod. Here, the Pod wraps around an application that’s composed of multiple containers and share resources.
If we need to run multiple containers within a single Pod, it’s recommended that we only do this in cases where the containers are tightly coupled.
kind — This defines what kind of Kubernetes object we want to create.
metadata — This is data that helps us uniquely identify the object that we want to create. Here we can provide a name for our app, as well as apply labels to our object.
spec — This defines the state that we want or our object. The format that we use for spec. For our Pod file, we have provided information about the containers that we want to host on our Pod.
Kubernetes relies on Probes to determine whether or not a Pod is healthy. Probes are diagnostic operations that are performed periodically by the Kubelet on containers.
There are three types of Probes:
Liveness Probes — These are used to determine if a Pod is healthy and running as expected. If the liveness probe fails, kubelet will kill the container and the container will then restart according to its defined policy (We can define these as either Always, OnFailure and Never)
Readiness Probes — These are use to determine whether or not a pod should receive requests. If the probe fails, the endpoints controller removes the IP address of the Pod from the endpoints of all Services that match the Pod.
Startup Probe — This is used to determine whether the container has started. All other probes are disabled if a startup probe is provided until it succeeds.
apiVersion — This defines the Kubernetes API version that we want to use in this YAML file. You can read more about API versioning in Kubernetes .