kubernetes-101-deployments
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).
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx // label matching the one in the selector
spec:
replicas: 3 // number of pods to be running at anytime
selector:
matchLabels:
app: nginx // which pods belong to this deployment
template:
metadata:
labels: app: nginx
spec: // pod template
containers:
- name: nginx-container
image: nginx:1.14.2
ports:
- 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!