Box

Allgemein

Profil

Deployment vs StatefulSet » Historie » Zyklus 1

Peter Pfläging, 18.03.2022 16:17

1 1 Peter Pfläging
# Deployment-vs-StatefulSet
2
3
Taking PostgreSQL as example:
4
5
## StatefulSet
6
7
```yaml
8
kind: StatefulSet
9
apiVersion: apps/v1
10
metadata:
11
  name: postgresql
12
spec:
13
  replicas: 1
14
  serviceName: postgresql
15
  selector:
16
    matchLabels:
17
      app: postgresql
18
  template:
19
    metadata:
20
      creationTimestamp: null
21
      labels:
22
        app: postgresql
23
    spec:
24
      containers:
25
        - name: postgresql
26
          image: docker.io/centos/postgresql-12-centos8:latest
27
          envFrom:
28
            - secretRef:
29
                name: database
30
          ports:
31
            - name: postgresql
32
              containerPort: 5432
33
              protocol: TCP
34
          resources:
35
            requests:
36
              cpu: "200m"
37
              memory: "128Mi"
38
            limits:
39
              cpu: "400m"
40
              memory: "256Mi"
41
          readinessProbe:
42
            tcpSocket:
43
              port: 5432
44
            timeoutSeconds: 1
45
            periodSeconds: 10
46
            successThreshold: 1
47
            failureThreshold: 3
48
          livenessProbe:
49
            tcpSocket:
50
              port: 5432
51
            timeoutSeconds: 1
52
            periodSeconds: 10
53
            successThreshold: 1
54
            failureThreshold: 3
55
          volumeMounts:
56
            - name: postgresql
57
              mountPath: /var/lib/pgsql/data
58
          terminationMessagePath: /dev/termination-log
59
          terminationMessagePolicy: File
60
          imagePullPolicy: Always
61
      restartPolicy: Always
62
      terminationGracePeriodSeconds: 10
63
      dnsPolicy: ClusterFirst
64
      securityContext: {}
65
      schedulerName: default-scheduler
66
  volumeClaimTemplates:
67
    - metadata:
68
        name: postgresql
69
        labels:
70
          app: postgresql
71
      spec:
72
        accessModes:
73
          - ReadWriteOnce
74
        storageClassName: changed-by-upper-kustomize
75
        volumeMode: Filesystem
76
        resources:
77
          requests:
78
            storage: 500Mi
79
```
80
81
## Deployment
82
83
Here we have a split. We have to explicit declare the PVC:
84
85
```yaml
86
---
87
kind: Deployment
88
apiVersion: apps/v1
89
metadata:
90
  name: postgresql
91
spec:
92
  replicas: 1
93
  selector:
94
    matchLabels:
95
      app: postgresql
96
  template:
97
    metadata:
98
      labels:
99
        app: postgresql
100
    spec:
101
      containers:
102
        - name: postgresql
103
          image: docker.io/centos/postgresql-12-centos8:latest
104
          envFrom:
105
            - secretRef:
106
                name: database
107
          resources:
108
            requests:
109
              cpu: "200m"
110
              memory: "128Mi"
111
            limits:
112
              cpu: "400m"
113
              memory: "256Mi"
114
          readinessProbe:
115
            tcpSocket:
116
              port: 5432
117
            timeoutSeconds: 1
118
            periodSeconds: 10
119
            successThreshold: 1
120
            failureThreshold: 3
121
          livenessProbe:
122
            tcpSocket:
123
              port: 5432
124
            timeoutSeconds: 1
125
            periodSeconds: 10
126
            successThreshold: 1
127
            failureThreshold: 3
128
          volumeMounts:
129
            - name: postgresql
130
              mountPath: /var/lib/pgsql/data
131
          terminationMessagePath: /dev/termination-log
132
          terminationMessagePolicy: File
133
          imagePullPolicy: Always
134
      restartPolicy: Always
135
      terminationGracePeriodSeconds: 10
136
      dnsPolicy: ClusterFirst
137
      securityContext: {}
138
      schedulerName: default-scheduler
139
      volumes:
140
      - name: postgresql
141
        persistentVolumeClaim:
142
          claimName: postgresql
143
  strategy:
144
    type: RollingUpdate
145
    rollingUpdate:
146
      maxUnavailable: 25%
147
      maxSurge: 25%
148
  revisionHistoryLimit: 10
149
  progressDeadlineSeconds: 600
150
---
151
kind: PersistentVolumeClaim
152
apiVersion: v1
153
metadata:
154
  name: postgresql
155
spec:
156
  accessModes:
157
    - ReadWriteOnce
158
  resources:
159
    requests:
160
      storage: 2Gi
161
  storageClassName: changed-by-upper-kustomize
162
  volumeMode: Filesystem
163
```