While you can't rely on any single pod to stay running indefinitely, you can rely on the fact that the cluster will always try to have the number of pods you wanted available.
A Deployment object contains a collection of pods defined by a template and a replica count (how many copies of the template we want to run).
app: nginx // label matching the one in the selector
replicas: 3 // number of pods to be running at anytime
app: nginx // which pods belong to this deployment
labels: app: nginx
spec: // pod template
- name: nginx-container
- containerPort: 80
If a pod stops from any given reason, the deployment controller (take a look on the Kubernetes - Cluster internals post) will work in conjunction with the scheduler to start a new pod based on the template defined in the deployment.
Even more, let’s say we have a Deployment with a replica count of 10 and a node crashes where we had 3 pods running.
3 more pods will be scheduled to run on a different running machine in the cluster.
For this reason, Deployments are best suited for stateless applications where Pods are able to be replaced at any time without breaking stuff and 0 downtime.
Running it is as easy as:
>> kubectl apply -f nginx-deployment.yaml
Check out new-spike.net for other articles on Kubernetes and much more!