17 Ekim 2022 Pazartesi

Kubernetes kind : Deployment Strategy RollingUpdate

Giriş
Açıklaması şöyle. Yani geriye uyumluluk vardır ve hizmette kesinti olmaz.
1. In this strategy, we do not drop all the already running instances.
2. We drop instances by a certain percentage at a time and simultaneously spawn equal percentage of newer version pods.
3. This upgrade is the default strategy in K8s.
4. This has no downtime.
Örnek
Şöyle yaparız. RollingUpdate ile yeni deployment yapılınca eski podlar yavaş yavaş kapatılır ve yeni podlar yavaş yavaş açılır
kind: Deployment
apiVersion: apps/v1
metadata:
  name: example-zookeeper
  namespace: kafka-example
  labels:
    app: example-zookeeper
spec:
  replicas: 1
  selector:
    matchLabels:
      app: example-zookeeper
  template:
    metadata:
      labels:
        app: example-zookeeper
    spec:
      containers:
        - name: example-zookeeper
          image: jplock/zookeeper
          ports:
            - containerPort: 2181
              protocol: TCP
          imagePullPolicy: IfNotPresent
      restartPolicy: Always
      dnsPolicy: ClusterFirst
      schedulerName: default-scheduler
      enableServiceLinks: true
  strategy:
    type: RollingUpdate
maxSurge ve maxUnavailable Alanları Neden Lazım ?
Çünkü RollingUpdate ile eski ve yeni pod'lar birlikte çalışırlar. Yeni pod'u yaratırken istenilen replica sayısı geçici olarak aşılır. maxSurge ile bu aşma miktarı kontrol edilir. maxUnavailable ile de her seferindeki en fazla kaç tane Pod'un kullanım dışı (unavailable) olabileceği belirtilir. Böylece hizmette kesinti sınırlandırılır

maxSurge Alanı
Varsayılan değer 1. 
Açıklaması şöyle. Sayı veya yüzde ile belirtilir. İstenilen replica sayısının geçici olarak ne kadar daha aşılabileceğini belirtir.
The maxSurge property controls the maximum number of additional pods that can be created during a rolling update. It specifies the number or percentage of pods above the desired replica count that can be temporarily created. During an update, Kubernetes creates new pods to replace the old ones, and the maxSurge property ensures that the total number of pods does not exceed a certain limit.
Açıklaması şöyle
The values for maxSurge and maxUnavailable can be specified in two formats: absolute numbers and percentages.

- Absolute Numbers: You can set a fixed number of pods as the value for maxSurge and maxUnavailable. For example, maxSurge: 2 means that a maximum of 2 additional pods can be created, and maxUnavailable: 1 indicates that a maximum of 1 pod can be unavailable at a time.

- Percentages: You can specify the values as percentages of the desired replica count. For example, maxSurge: 50% means that 50% of the desired replica count can be temporarily exceeded, and maxUnavailable: 25% indicates that 25% of the desired replica count can be unavailable.
Örnek
Şöyle yaparız
strategy:
  type : RollingUpdate
  rollingUpdate:
    type: RollingUpdate
      maxSurge : 25%
      maxUnavailable : 25%
Açıklaması şöyle
spec.strategy.rollingUpdate.maxSurge 
as 25% specifying the maximum number of Pods that can be created over the required replica number.
spec.strategy.rollingUpdate.maxUnavailable 
as 25% which allows upto 25% of pods can be unavailable during a deployment.
maxUnavailable Alanı
Varsayılan değer %25.
Açıklaması şöyle. Sayı veya yüzde ile belirtilir. Bir seferde toplam kaç tane pod'un unavailable olabileceğini belirtir.
The maxUnavailable property determines the maximum number or percentage of pods that can be unavailable during a rolling update. It specifies the maximum number of pods that can be simultaneously removed from service during the update progresses. By default, Kubernetes terminates one pod at a time while creating new pods, ensuring that the desired replica count is maintained.
Örnek
Şöyle yaparız
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-deployment
spec:
  replicas: 3
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
        - name: my-container
          image: my-image:latest
          ports:
            - containerPort: 8080
Açıklaması şöyle
In this example, we have set both maxSurge and maxUnavailable to 1, indicating that during the rolling update, one additional pod can be created and one pod can be unavailable at a time
Bazı senaryolar
Açıklaması şöyle
Let’s explore few scenarios.

Scenario 1: maxSurge: 1, maxUnavailable: 0

Desired replica count: 3
During the update, Kubernetes creates 1 additional pod at a time while keeping all existing pods running.
No pods are removed before the new pods become ready.

Scenario 2: maxSurge: 0, maxUnavailable: 1

Desired replica count: 3
During the update, no additional pods are created (maxSurge: 0), but one pod can be unavailable (maxUnavailable: 1).
Kubernetes terminates one pod at a time, ensuring that the desired replica count is maintained. So, at any given time, there will be 2 pods running and 1 pod unavailable.

Scenario 3: maxSurge: 25%, maxUnavailable: 25%

Desired replica count: 4
During the update, Kubernetes can create up to 25% of the desired replica count as additional pods (maxSurge: 25%). In this case, it can create a maximum of 1 additional pod.
Similarly, up to 25% of the desired replica count can be unavailable (maxUnavailable: 25%). In this case, it can have a maximum of 1 pod unavailable at a time.
This allows flexibility during the update process, ensuring that there is no significant impact on the availability of the application.


Hiç yorum yok:

Yorum Gönder

Cluster Propotional Autoscaler - ReplicaSet Ekler/Siler

Giriş Açıklaması şöyle CPA aims to horizontally scale the number of Pod replicas based on the cluster’s scale. A common example is DNS ser...