3.4 KiB
Deployment types
-
There are many different ways to deploy services
-
Having an understandig of the differences helps to choose the best one
Simple POD
-
An easy thing to deploy is a Pod
-
A pod is limited in its ability and therefor often not created manually
-
(Cron)jobs, deployments, daemonsets and statefulsets all create (and manage!) pods
- This allows for better management, scaling etc. (where applicable)
Jobs
-
Are one time executions of a Pod
-
Often used to perform a one time action
-
Triggered manually or on a time schedule in which case it is a cron job.
-
Uses a pod template to create pods
-
.small[
apiVersion: batch/v1
kind: Job
metadata:
name: pi
spec:
template:
spec:
containers:
- name: pi
image: perl:5.34.0
command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
restartPolicy: Never
backoffLimit: 4
]
Deployments
-
The most common deployment types
-
They create Replica Sets
-
Are scalable (manually or automatically)
-
Enablers of rolling updates
-
Used for rollback scenarios
-
-
Use a pod template to create pods (Using resource sets as intermediates)
-
Share PVC's amongst pods
-
.small[
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
]
Statefulsets
-
Less commonly used
-
Scale like Deployments, but slightly different
-
Do NOT share PVC's but have individual ones
-
Differ in update process
-
-
Use a pod template to create pods
.small[
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web
spec:
selector:
matchLabels:
app: nginx # has to match .spec.template.metadata.labels
serviceName: "nginx"
replicas: 3 # by default is 1
template:
metadata:
labels:
app: nginx # has to match .spec.selector.matchLabels
spec:
terminationGracePeriodSeconds: 10
containers:
- name: nginx
image: registry.k8s.io/nginx-slim:0.8
ports:
- containerPort: 80
name: web
volumeMounts:
- name: www
mountPath: /usr/share/nginx/html
volumeClaimTemplates:
- metadata:
name: www
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: "my-storage-class"
resources:
requests:
storage: 1Gi
]
Daemonset
-
Deploy one pod per node
-
Not more, not less
-
Each new node automatically get's a pod
-
-
Use a pod template to create pods
.small[
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: fluentd-elasticsearch
namespace: kube-system
labels:
k8s-app: fluentd-logging
spec:
selector:
matchLabels:
name: fluentd-elasticsearch
template:
metadata:
labels:
name: fluentd-elasticsearch
spec:
containers:
- name: fluentd-elasticsearch
image: "quay.io/fluentd_elasticsearch/fluentd:v2.5.2"
volumeMounts:
- name: varlog
mountPath: /var/log
terminationGracePeriodSeconds: 30
volumes:
- name: varlog
hostPath:
path: /var/log
]